diff --git a/libs/core/src/main/java/org/elasticsearch/core/Types.java b/libs/core/src/main/java/org/elasticsearch/core/Types.java new file mode 100644 index 0000000000000..e1cf533d4eab4 --- /dev/null +++ b/libs/core/src/main/java/org/elasticsearch/core/Types.java @@ -0,0 +1,28 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License + * 2.0 and the Server Side Public License, v 1; you may not use this file except + * in compliance with, at your election, the Elastic License 2.0 or the Server + * Side Public License, v 1. + */ + +package org.elasticsearch.core; + +/** + * Contains utilities for working with Java types. + */ +public abstract class Types { + + /** + * There are some situations where we cannot appease javac's type checking, and we + * need to forcibly cast an object's type. Please don't use this method unless you + * have no choice. + * @param argument the object to cast + * @param the inferred type to which to cast the argument + * @return a cast version of the argument + */ + @SuppressWarnings("unchecked") + public static T forciblyCast(Object argument) { + return (T) argument; + } +} diff --git a/server/src/main/java/org/elasticsearch/action/admin/indices/validate/query/TransportValidateQueryAction.java b/server/src/main/java/org/elasticsearch/action/admin/indices/validate/query/TransportValidateQueryAction.java index b2c7cc8205b35..27f5c38f52aef 100644 --- a/server/src/main/java/org/elasticsearch/action/admin/indices/validate/query/TransportValidateQueryAction.java +++ b/server/src/main/java/org/elasticsearch/action/admin/indices/validate/query/TransportValidateQueryAction.java @@ -20,6 +20,7 @@ import org.elasticsearch.cluster.block.ClusterBlockLevel; import org.elasticsearch.cluster.metadata.IndexNameExpressionResolver; import org.elasticsearch.cluster.routing.GroupShardsIterator; +import org.elasticsearch.cluster.routing.ShardIterator; import org.elasticsearch.cluster.routing.ShardRouting; import org.elasticsearch.cluster.service.ClusterService; import org.elasticsearch.common.ParsingException; @@ -118,7 +119,7 @@ protected ShardValidateQueryResponse readShardResponse(StreamInput in) throws IO } @Override - protected GroupShardsIterator shards(ClusterState clusterState, ValidateQueryRequest request, String[] concreteIndices) { + protected GroupShardsIterator shards(ClusterState clusterState, ValidateQueryRequest request, String[] concreteIndices) { final String routing; if (request.allShards()) { routing = null; diff --git a/server/src/main/java/org/elasticsearch/action/bulk/BulkPrimaryExecutionContext.java b/server/src/main/java/org/elasticsearch/action/bulk/BulkPrimaryExecutionContext.java index 148e8850283af..25ca86114e250 100644 --- a/server/src/main/java/org/elasticsearch/action/bulk/BulkPrimaryExecutionContext.java +++ b/server/src/main/java/org/elasticsearch/action/bulk/BulkPrimaryExecutionContext.java @@ -61,7 +61,7 @@ enum ItemProcessingState { private int currentIndex = -1; private ItemProcessingState currentItemState; - private DocWriteRequest requestToExecute; + private DocWriteRequest requestToExecute; private BulkItemResponse executionResult; private int retryCounter; @@ -182,7 +182,7 @@ public IndexShard getPrimary() { * sets the request that should actually be executed on the primary. This can be different then the request * received from the user (specifically, an update request is translated to an indexing or delete request). */ - public void setRequestToExecute(DocWriteRequest writeRequest) { + public void setRequestToExecute(DocWriteRequest writeRequest) { assert assertInvariants(ItemProcessingState.INITIAL); requestToExecute = writeRequest; currentItemState = ItemProcessingState.TRANSLATED; @@ -190,6 +190,7 @@ public void setRequestToExecute(DocWriteRequest writeRequest) { } /** returns the request that should be executed on the shard. */ + @SuppressWarnings("unchecked") public > T getRequestToExecute() { assert assertInvariants(ItemProcessingState.TRANSLATED); return (T) requestToExecute; @@ -224,7 +225,7 @@ public void markOperationAsNoOp(DocWriteResponse response) { public void failOnMappingUpdate(Exception cause) { assert assertInvariants(ItemProcessingState.WAIT_FOR_MAPPING_UPDATE); currentItemState = ItemProcessingState.EXECUTED; - final DocWriteRequest docWriteRequest = getCurrentItem().request(); + final DocWriteRequest docWriteRequest = getCurrentItem().request(); executionResult = new BulkItemResponse(getCurrentItem().id(), docWriteRequest.opType(), // Make sure to use getCurrentItem().index() here, if you use docWriteRequest.index() it will use the // concrete index instead of an alias if used! @@ -236,7 +237,7 @@ public void failOnMappingUpdate(Exception cause) { public void markOperationAsExecuted(Engine.Result result) { assertInvariants(ItemProcessingState.TRANSLATED); final BulkItemRequest current = getCurrentItem(); - DocWriteRequest docWriteRequest = getRequestToExecute(); + DocWriteRequest docWriteRequest = getRequestToExecute(); switch (result.getResultType()) { case SUCCESS: final DocWriteResponse response; diff --git a/server/src/main/java/org/elasticsearch/action/bulk/TransportSingleItemBulkWriteAction.java b/server/src/main/java/org/elasticsearch/action/bulk/TransportSingleItemBulkWriteAction.java index 2daff4559d960..615c7d5336225 100644 --- a/server/src/main/java/org/elasticsearch/action/bulk/TransportSingleItemBulkWriteAction.java +++ b/server/src/main/java/org/elasticsearch/action/bulk/TransportSingleItemBulkWriteAction.java @@ -10,7 +10,6 @@ import org.elasticsearch.action.ActionListener; import org.elasticsearch.action.DocWriteRequest; -import org.elasticsearch.action.DocWriteResponse; import org.elasticsearch.action.support.ActionFilters; import org.elasticsearch.action.support.HandledTransportAction; import org.elasticsearch.action.support.WriteRequest; @@ -47,8 +46,9 @@ ActionListener wrapBulkResponse(ActionListener listener) assert bulkItemResponses.getItems().length == 1 : "expected only one item in bulk request"; BulkItemResponse bulkItemResponse = bulkItemResponses.getItems()[0]; if (bulkItemResponse.isFailed() == false) { - final DocWriteResponse response = bulkItemResponse.getResponse(); - listener.onResponse((Response) response); + @SuppressWarnings("unchecked") + final Response response = (Response) bulkItemResponse.getResponse(); + listener.onResponse(response); } else { listener.onFailure(bulkItemResponse.getFailure().getCause()); } diff --git a/server/src/main/java/org/elasticsearch/action/ingest/IngestActionForwarder.java b/server/src/main/java/org/elasticsearch/action/ingest/IngestActionForwarder.java index b2f240b036935..be4410b838271 100644 --- a/server/src/main/java/org/elasticsearch/action/ingest/IngestActionForwarder.java +++ b/server/src/main/java/org/elasticsearch/action/ingest/IngestActionForwarder.java @@ -36,6 +36,7 @@ public IngestActionForwarder(TransportService transportService) { ingestNodes = new DiscoveryNode[0]; } + @SuppressWarnings({"rawtypes", "unchecked"}) public void forwardIngestRequest(ActionType action, ActionRequest request, ActionListener listener) { transportService.sendRequest(randomIngestNode(), action.name(), request, new ActionListenerResponseHandler(listener, action.getResponseReader())); diff --git a/server/src/main/java/org/elasticsearch/action/support/broadcast/TransportBroadcastAction.java b/server/src/main/java/org/elasticsearch/action/support/broadcast/TransportBroadcastAction.java index 4470700752d51..cf948fa90b5e6 100644 --- a/server/src/main/java/org/elasticsearch/action/support/broadcast/TransportBroadcastAction.java +++ b/server/src/main/java/org/elasticsearch/action/support/broadcast/TransportBroadcastAction.java @@ -100,7 +100,8 @@ protected class AsyncBroadcastAction { final GroupShardsIterator shardsIts; final int expectedOps; final AtomicInteger counterOps = new AtomicInteger(); - protected final AtomicReferenceArray shardsResponses; + // ShardResponse or Exception + protected final AtomicReferenceArray shardsResponses; protected AsyncBroadcastAction(Task task, Request request, ActionListener listener) { this.task = task; @@ -132,7 +133,7 @@ public void start() { if (shardsIts.size() == 0) { // no shards try { - listener.onResponse(newResponse(request, new AtomicReferenceArray(0), clusterState)); + listener.onResponse(newResponse(request, new AtomicReferenceArray(0), clusterState)); } catch (Exception e) { listener.onFailure(e); } @@ -189,7 +190,6 @@ public void handleException(TransportException e) { } } - @SuppressWarnings({"unchecked"}) protected void onOperation(ShardRouting shard, int shardIndex, ShardResponse response) { logger.trace("received response for {}", shard); shardsResponses.set(shardIndex, response); @@ -228,7 +228,7 @@ void onOperation(@Nullable ShardRouting shard, final ShardIterator shardIt, int } } - protected AtomicReferenceArray shardsResponses() { + protected AtomicReferenceArray shardsResponses() { return shardsResponses; } diff --git a/server/src/main/java/org/elasticsearch/action/support/tasks/TransportTasksAction.java b/server/src/main/java/org/elasticsearch/action/support/tasks/TransportTasksAction.java index e01173a037f79..fd7f308e14419 100644 --- a/server/src/main/java/org/elasticsearch/action/support/tasks/TransportTasksAction.java +++ b/server/src/main/java/org/elasticsearch/action/support/tasks/TransportTasksAction.java @@ -147,6 +147,7 @@ protected String[] resolveNodes(TasksRequest request, ClusterState clusterState) } } + @SuppressWarnings("unchecked") protected void processTasks(TasksRequest request, Consumer operation) { if (request.getTaskId().isSet()) { // we are only checking one task, we can optimize it @@ -173,7 +174,7 @@ protected abstract TasksResponse newResponse(TasksRequest request, List failedNodeExceptions); @SuppressWarnings("unchecked") - protected TasksResponse newResponse(TasksRequest request, AtomicReferenceArray responses) { + protected TasksResponse newResponse(TasksRequest request, AtomicReferenceArray responses) { List tasks = new ArrayList<>(); List failedNodeExceptions = new ArrayList<>(); List taskOperationFailures = new ArrayList<>(); diff --git a/server/src/main/java/org/elasticsearch/common/collect/Iterators.java b/server/src/main/java/org/elasticsearch/common/collect/Iterators.java index 1648f122f0739..e813412260a14 100644 --- a/server/src/main/java/org/elasticsearch/common/collect/Iterators.java +++ b/server/src/main/java/org/elasticsearch/common/collect/Iterators.java @@ -36,6 +36,8 @@ public T next() { }; } + @SafeVarargs + @SuppressWarnings("varargs") public static Iterator concat(Iterator... iterators) { if (iterators == null) { throw new NullPointerException("iterators"); @@ -49,6 +51,8 @@ static class ConcatenatedIterator implements Iterator { private final Iterator[] iterators; private int index = 0; + @SafeVarargs + @SuppressWarnings("varargs") ConcatenatedIterator(Iterator... iterators) { if (iterators == null) { throw new NullPointerException("iterators"); diff --git a/server/src/main/java/org/elasticsearch/common/geo/builders/GeometryCollectionBuilder.java b/server/src/main/java/org/elasticsearch/common/geo/builders/GeometryCollectionBuilder.java index ff4db16da9668..299735b786fbc 100644 --- a/server/src/main/java/org/elasticsearch/common/geo/builders/GeometryCollectionBuilder.java +++ b/server/src/main/java/org/elasticsearch/common/geo/builders/GeometryCollectionBuilder.java @@ -33,7 +33,7 @@ public class GeometryCollectionBuilder extends ShapeBuilder shapes = new ArrayList<>(); + final List> shapes = new ArrayList<>(); /** * Build and empty GeometryCollectionBuilder. @@ -54,12 +54,12 @@ public GeometryCollectionBuilder(StreamInput in) throws IOException { @Override public void writeTo(StreamOutput out) throws IOException { out.writeVInt(shapes.size()); - for (ShapeBuilder shape : shapes) { + for (ShapeBuilder shape : shapes) { out.writeNamedWriteable(shape); } } - public GeometryCollectionBuilder shape(ShapeBuilder shape) { + public GeometryCollectionBuilder shape(ShapeBuilder shape) { this.shapes.add(shape); return this; } @@ -104,7 +104,7 @@ public GeometryCollectionBuilder circle(CircleBuilder circle) { return this; } - public ShapeBuilder getShapeAt(int i) { + public ShapeBuilder getShapeAt(int i) { if (i >= this.shapes.size() || i < 0) { throw new ElasticsearchException("GeometryCollection contains " + this.shapes.size() + " shapes. + " + "No shape found at index " + i); @@ -121,7 +121,7 @@ public XContentBuilder toXContent(XContentBuilder builder, Params params) throws builder.startObject(); builder.field(ShapeParser.FIELD_TYPE.getPreferredName(), TYPE.shapeName()); builder.startArray(ShapeParser.FIELD_GEOMETRIES.getPreferredName()); - for (ShapeBuilder shape : shapes) { + for (ShapeBuilder shape : shapes) { shape.toXContent(builder, params); } builder.endArray(); @@ -164,7 +164,7 @@ public Shape buildS4J() { List shapes = new ArrayList<>(this.shapes.size()); - for (ShapeBuilder shape : this.shapes) { + for (ShapeBuilder shape : this.shapes) { shapes.add(shape.buildS4J()); } @@ -182,7 +182,7 @@ public GeometryCollection buildGeometry() { } List shapes = new ArrayList<>(this.shapes.size()); - for (ShapeBuilder shape : this.shapes) { + for (ShapeBuilder shape : this.shapes) { shapes.add(shape.buildGeometry()); } diff --git a/server/src/main/java/org/elasticsearch/common/geo/parsers/GeoJsonParser.java b/server/src/main/java/org/elasticsearch/common/geo/parsers/GeoJsonParser.java index d5117fd7e0aec..3608609212e16 100644 --- a/server/src/main/java/org/elasticsearch/common/geo/parsers/GeoJsonParser.java +++ b/server/src/main/java/org/elasticsearch/common/geo/parsers/GeoJsonParser.java @@ -30,7 +30,7 @@ * complies with geojson specification: https://tools.ietf.org/html/rfc7946 */ abstract class GeoJsonParser { - protected static ShapeBuilder parse(XContentParser parser, AbstractShapeGeometryFieldMapper shapeMapper) + protected static ShapeBuilder parse(XContentParser parser, AbstractShapeGeometryFieldMapper shapeMapper) throws IOException { GeoShapeType shapeType = null; DistanceUnit.Distance radius = null; @@ -80,7 +80,7 @@ protected static ShapeBuilder parse(XContentParser parser, AbstractShapeGeometry } else if (CircleBuilder.FIELD_RADIUS.match(fieldName, subParser.getDeprecationHandler())) { if (shapeType == null) { shapeType = GeoShapeType.CIRCLE; - } else if (shapeType != null && shapeType.equals(GeoShapeType.CIRCLE) == false) { + } else if (shapeType.equals(GeoShapeType.CIRCLE) == false) { malformedException = "cannot have [" + CircleBuilder.FIELD_RADIUS + "] with type set to [" + shapeType + "]"; } @@ -192,7 +192,7 @@ private static Coordinate parseCoordinate(XContentParser parser, boolean ignoreZ * @return Geometry[] geometries of the GeometryCollection * @throws IOException Thrown if an error occurs while reading from the XContentParser */ - static GeometryCollectionBuilder parseGeometries(XContentParser parser, AbstractShapeGeometryFieldMapper mapper) throws + static GeometryCollectionBuilder parseGeometries(XContentParser parser, AbstractShapeGeometryFieldMapper mapper) throws IOException { if (parser.currentToken() != XContentParser.Token.START_ARRAY) { throw new ElasticsearchParseException("geometries must be an array of geojson objects"); @@ -201,7 +201,7 @@ static GeometryCollectionBuilder parseGeometries(XContentParser parser, Abstract XContentParser.Token token = parser.nextToken(); GeometryCollectionBuilder geometryCollection = new GeometryCollectionBuilder(); while (token != XContentParser.Token.END_ARRAY) { - ShapeBuilder shapeBuilder = ShapeParser.parse(parser); + ShapeBuilder shapeBuilder = ShapeParser.parse(parser); geometryCollection.shape(shapeBuilder); token = parser.nextToken(); } diff --git a/server/src/main/java/org/elasticsearch/common/geo/parsers/GeoWKTParser.java b/server/src/main/java/org/elasticsearch/common/geo/parsers/GeoWKTParser.java index a87fefe478577..cf9e853add472 100644 --- a/server/src/main/java/org/elasticsearch/common/geo/parsers/GeoWKTParser.java +++ b/server/src/main/java/org/elasticsearch/common/geo/parsers/GeoWKTParser.java @@ -52,19 +52,19 @@ public class GeoWKTParser { // no instance private GeoWKTParser() {} - public static ShapeBuilder parse(XContentParser parser, final AbstractShapeGeometryFieldMapper shapeMapper) + public static ShapeBuilder parse(XContentParser parser, final AbstractShapeGeometryFieldMapper shapeMapper) throws IOException, ElasticsearchParseException { return parseExpectedType(parser, null, shapeMapper); } - public static ShapeBuilder parseExpectedType(XContentParser parser, final GeoShapeType shapeType) + public static ShapeBuilder parseExpectedType(XContentParser parser, final GeoShapeType shapeType) throws IOException, ElasticsearchParseException { return parseExpectedType(parser, shapeType, null); } /** throws an exception if the parsed geometry type does not match the expected shape type */ - public static ShapeBuilder parseExpectedType(XContentParser parser, final GeoShapeType shapeType, - final AbstractShapeGeometryFieldMapper shapeMapper) + public static ShapeBuilder parseExpectedType(XContentParser parser, final GeoShapeType shapeType, + final AbstractShapeGeometryFieldMapper shapeMapper) throws IOException, ElasticsearchParseException { try (StringReader reader = new StringReader(parser.text())) { boolean coerce = shapeMapper != null && shapeMapper.coerce(); @@ -81,14 +81,14 @@ public static ShapeBuilder parseExpectedType(XContentParser parser, final GeoSha tokenizer.wordChars('.', '.'); tokenizer.whitespaceChars(0, ' '); tokenizer.commentChar('#'); - ShapeBuilder builder = parseGeometry(tokenizer, shapeType, ignoreZValue, coerce); + ShapeBuilder builder = parseGeometry(tokenizer, shapeType, ignoreZValue, coerce); checkEOF(tokenizer); return builder; } } /** parse geometry from the stream tokenizer */ - private static ShapeBuilder parseGeometry(StreamTokenizer stream, GeoShapeType shapeType, final boolean ignoreZValue, + private static ShapeBuilder parseGeometry(StreamTokenizer stream, GeoShapeType shapeType, final boolean ignoreZValue, final boolean coerce) throws IOException, ElasticsearchParseException { final GeoShapeType type = GeoShapeType.forName(nextWord(stream)); diff --git a/server/src/main/java/org/elasticsearch/common/geo/parsers/ShapeParser.java b/server/src/main/java/org/elasticsearch/common/geo/parsers/ShapeParser.java index cb2c267cc6645..56f2fe3ff5205 100644 --- a/server/src/main/java/org/elasticsearch/common/geo/parsers/ShapeParser.java +++ b/server/src/main/java/org/elasticsearch/common/geo/parsers/ShapeParser.java @@ -40,13 +40,13 @@ public interface ShapeParser { * if the parsers current token has been null * @throws IOException if the input could not be read */ - static ShapeBuilder parse(XContentParser parser, AbstractGeometryFieldMapper geometryMapper) throws IOException { - AbstractShapeGeometryFieldMapper shapeMapper = null; + static ShapeBuilder parse(XContentParser parser, AbstractGeometryFieldMapper geometryMapper) throws IOException { + AbstractShapeGeometryFieldMapper shapeMapper = null; if (geometryMapper != null) { if (geometryMapper instanceof AbstractShapeGeometryFieldMapper == false) { throw new IllegalArgumentException("geometry must be a shape type"); } - shapeMapper = (AbstractShapeGeometryFieldMapper) geometryMapper; + shapeMapper = (AbstractShapeGeometryFieldMapper) geometryMapper; } if (parser.currentToken() == XContentParser.Token.VALUE_NULL) { return null; @@ -65,11 +65,11 @@ static ShapeBuilder parse(XContentParser parser, AbstractGeometryFieldMapper geo * if the parsers current token has been null * @throws IOException if the input could not be read */ - static ShapeBuilder parse(XContentParser parser) throws IOException { + static ShapeBuilder parse(XContentParser parser) throws IOException { return parse(parser, null); } - static ShapeBuilder parse(Object value) throws IOException { + static ShapeBuilder parse(Object value) throws IOException { try (XContentParser parser = new MapXContentParser(NamedXContentRegistry.EMPTY, LoggingDeprecationHandler.INSTANCE, Collections.singletonMap("value", value), null)) { parser.nextToken(); // start object diff --git a/server/src/main/java/org/elasticsearch/common/inject/ConstantFactory.java b/server/src/main/java/org/elasticsearch/common/inject/ConstantFactory.java index aa7029f2a9cae..2b92d1ad745bb 100644 --- a/server/src/main/java/org/elasticsearch/common/inject/ConstantFactory.java +++ b/server/src/main/java/org/elasticsearch/common/inject/ConstantFactory.java @@ -35,7 +35,7 @@ class ConstantFactory implements InternalFactory { } @Override - public T get(Errors errors, InternalContext context, Dependency dependency) + public T get(Errors errors, InternalContext context, Dependency dependency) throws ErrorsException { return initializable.get(errors); } diff --git a/server/src/main/java/org/elasticsearch/common/inject/InheritingState.java b/server/src/main/java/org/elasticsearch/common/inject/InheritingState.java index eb05b1dbe6e4d..70ff107a41de8 100644 --- a/server/src/main/java/org/elasticsearch/common/inject/InheritingState.java +++ b/server/src/main/java/org/elasticsearch/common/inject/InheritingState.java @@ -152,10 +152,11 @@ public void clearBlacklisted() { public void makeAllBindingsToEagerSingletons(Injector injector) { Map, Binding> x = new LinkedHashMap<>(); for (Map.Entry, Binding> entry : this.explicitBindingsMutable.entrySet()) { - Key key = entry.getKey(); + @SuppressWarnings("unchecked") + Key key = (Key) entry.getKey(); BindingImpl binding = (BindingImpl) entry.getValue(); Object value = binding.getProvider().get(); - x.put(key, new InstanceBindingImpl(injector, key, SourceProvider.UNKNOWN_SOURCE, new InternalFactory.Instance(value), + x.put(key, new InstanceBindingImpl<>(injector, key, SourceProvider.UNKNOWN_SOURCE, new InternalFactory.Instance<>(value), emptySet(), value)); } this.explicitBindingsMutable.clear(); diff --git a/server/src/main/java/org/elasticsearch/common/inject/InjectionRequestProcessor.java b/server/src/main/java/org/elasticsearch/common/inject/InjectionRequestProcessor.java index 909779cb442a6..4b4e163ef400a 100644 --- a/server/src/main/java/org/elasticsearch/common/inject/InjectionRequestProcessor.java +++ b/server/src/main/java/org/elasticsearch/common/inject/InjectionRequestProcessor.java @@ -51,7 +51,7 @@ public Boolean visit(StaticInjectionRequest request) { } @Override - public Boolean visit(InjectionRequest request) { + public Boolean visit(InjectionRequest request) { Set injectionPoints; try { injectionPoints = request.getInjectionPoints(); diff --git a/server/src/main/java/org/elasticsearch/common/inject/InjectorImpl.java b/server/src/main/java/org/elasticsearch/common/inject/InjectorImpl.java index e2ee9aa8eee34..fd37a52bead54 100644 --- a/server/src/main/java/org/elasticsearch/common/inject/InjectorImpl.java +++ b/server/src/main/java/org/elasticsearch/common/inject/InjectorImpl.java @@ -206,7 +206,7 @@ static InternalFactory> createInternalFactory(Binding provide final Provider provider = providedBinding.getProvider(); return new InternalFactory>() { @Override - public Provider get(Errors errors, InternalContext context, Dependency dependency) { + public Provider get(Errors errors, InternalContext context, Dependency dependency) { return provider; } }; @@ -473,7 +473,7 @@ BindingImpl createProvidedByBinding(Key key, Scoping scoping, InternalFactory internalFactory = new InternalFactory() { @Override - public T get(Errors errors, InternalContext context, Dependency dependency) + public T get(Errors errors, InternalContext context, Dependency dependency) throws ErrorsException { errors = errors.withSource(providerKey); Provider provider = providerBinding.getInternalFactory().get( @@ -585,7 +585,7 @@ BindingImpl createJustInTimeBinding(Key key, Errors errors) throws Err // These casts are safe. We know T extends Provider and that given Key>, // createProviderBinding() will return BindingImpl>. @SuppressWarnings("unchecked") - BindingImpl binding = createProviderBinding((Key) key, errors); + BindingImpl binding = (BindingImpl) createProviderBinding((Key>) key, errors); return binding; } @@ -594,7 +594,7 @@ BindingImpl createJustInTimeBinding(Key key, Errors errors) throws Err // These casts are safe. T extends MembersInjector and that given Key>, // createMembersInjectorBinding() will return BindingImpl>. @SuppressWarnings("unchecked") - BindingImpl binding = createMembersInjectorBinding((Key) key, errors); + BindingImpl binding = (BindingImpl) createMembersInjectorBinding((Key>) key, errors); return binding; } @@ -701,9 +701,9 @@ Object invoke(Object target, Object... parameters) MembersInjectorStore membersInjectorStore; @Override - @SuppressWarnings("unchecked") // the members injector type is consistent with instance's type public void injectMembers(Object instance) { - MembersInjector membersInjector = getMembersInjector(instance.getClass()); + @SuppressWarnings("unchecked") // the members injector type is consistent with instance's type + MembersInjector membersInjector = getMembersInjector((Class) instance.getClass()); membersInjector.injectMembers(instance); } @@ -733,9 +733,10 @@ Provider getProviderOrThrow(final Key key, Errors errors) throws Error if (factory instanceof InternalFactory.Instance) { return new Provider() { @Override + @SuppressWarnings("unchecked") public T get() { try { - return (T) ((InternalFactory.Instance) factory).get(null, null, null); + return (T) ((InternalFactory.Instance) factory).get(null, null, null); } catch (ErrorsException e) { // ignore } diff --git a/server/src/main/java/org/elasticsearch/common/inject/ProviderToInternalFactoryAdapter.java b/server/src/main/java/org/elasticsearch/common/inject/ProviderToInternalFactoryAdapter.java index f443756908867..2a710c6d24cdd 100644 --- a/server/src/main/java/org/elasticsearch/common/inject/ProviderToInternalFactoryAdapter.java +++ b/server/src/main/java/org/elasticsearch/common/inject/ProviderToInternalFactoryAdapter.java @@ -43,7 +43,7 @@ public T get() { T t = injector.callInContext(new ContextualCallable() { @Override public T call(InternalContext context) throws ErrorsException { - Dependency dependency = context.getDependency(); + Dependency dependency = context.getDependency(); return internalFactory.get(errors, context, dependency); } }); diff --git a/server/src/main/java/org/elasticsearch/common/inject/assistedinject/FactoryProvider.java b/server/src/main/java/org/elasticsearch/common/inject/assistedinject/FactoryProvider.java index b99e3ac75c30f..32347cdd44b36 100644 --- a/server/src/main/java/org/elasticsearch/common/inject/assistedinject/FactoryProvider.java +++ b/server/src/main/java/org/elasticsearch/common/inject/assistedinject/FactoryProvider.java @@ -216,7 +216,7 @@ public Object[] gatherArgsForConstructor( @SuppressWarnings("unchecked") // we imprecisely treat the class literal of T as a Class Class factoryRawType = (Class) factoryType.getRawType(); return factoryRawType.cast(Proxy.newProxyInstance(factoryRawType.getClassLoader(), - new Class[]{factoryRawType}, invocationHandler)); + new Class[]{factoryRawType}, invocationHandler)); } private static ConfigurationException newConfigurationException(String format, Object... args) { diff --git a/server/src/main/java/org/elasticsearch/common/inject/internal/ConstructionContext.java b/server/src/main/java/org/elasticsearch/common/inject/internal/ConstructionContext.java index 3127fb97efdcc..43124988ade2b 100644 --- a/server/src/main/java/org/elasticsearch/common/inject/internal/ConstructionContext.java +++ b/server/src/main/java/org/elasticsearch/common/inject/internal/ConstructionContext.java @@ -82,7 +82,7 @@ public Object createProxy(Errors errors, Class expectedType) throws ErrorsExc ClassLoader classLoader = expectedType.getClassLoader() == null ? ClassLoader.getSystemClassLoader() : expectedType.getClassLoader(); return expectedType.cast(Proxy.newProxyInstance(classLoader, - new Class[]{expectedType}, invocationHandler)); + new Class[]{expectedType}, invocationHandler)); } public void setProxyDelegates(T delegate) { diff --git a/server/src/main/java/org/elasticsearch/common/inject/internal/InternalContext.java b/server/src/main/java/org/elasticsearch/common/inject/internal/InternalContext.java index 1184a97edc293..6d53bb2c40da6 100644 --- a/server/src/main/java/org/elasticsearch/common/inject/internal/InternalContext.java +++ b/server/src/main/java/org/elasticsearch/common/inject/internal/InternalContext.java @@ -30,7 +30,7 @@ public final class InternalContext { private Map> constructionContexts = new HashMap<>(); - private Dependency dependency; + private Dependency dependency; @SuppressWarnings("unchecked") public ConstructionContext getConstructionContext(Object key) { @@ -43,11 +43,11 @@ public ConstructionContext getConstructionContext(Object key) { return constructionContext; } - public Dependency getDependency() { + public Dependency getDependency() { return dependency; } - public void setDependency(Dependency dependency) { + public void setDependency(Dependency dependency) { this.dependency = dependency; } } diff --git a/server/src/main/java/org/elasticsearch/common/inject/internal/StackTraceElements.java b/server/src/main/java/org/elasticsearch/common/inject/internal/StackTraceElements.java index 5589c7b3082a9..85542bdba90e0 100644 --- a/server/src/main/java/org/elasticsearch/common/inject/internal/StackTraceElements.java +++ b/server/src/main/java/org/elasticsearch/common/inject/internal/StackTraceElements.java @@ -31,7 +31,7 @@ public static Object forMember(Member member) { return SourceProvider.UNKNOWN_SOURCE; } - Class declaringClass = member.getDeclaringClass(); + Class declaringClass = member.getDeclaringClass(); String fileName = null; int lineNumber = -1; diff --git a/server/src/main/java/org/elasticsearch/common/inject/internal/ToStringBuilder.java b/server/src/main/java/org/elasticsearch/common/inject/internal/ToStringBuilder.java index 4e975280cb768..d955d3be42053 100644 --- a/server/src/main/java/org/elasticsearch/common/inject/internal/ToStringBuilder.java +++ b/server/src/main/java/org/elasticsearch/common/inject/internal/ToStringBuilder.java @@ -35,7 +35,7 @@ public ToStringBuilder(String name) { this.name = name; } - public ToStringBuilder(Class type) { + public ToStringBuilder(Class type) { this.name = type.getSimpleName(); } diff --git a/server/src/main/java/org/elasticsearch/common/inject/matcher/Matchers.java b/server/src/main/java/org/elasticsearch/common/inject/matcher/Matchers.java index 4d6e0e28a5de0..7bce314a6b8e9 100644 --- a/server/src/main/java/org/elasticsearch/common/inject/matcher/Matchers.java +++ b/server/src/main/java/org/elasticsearch/common/inject/matcher/Matchers.java @@ -81,7 +81,7 @@ public boolean matches(T t) { @Override public boolean equals(Object other) { return other instanceof Not - && ((Not) other).delegate.equals(delegate); + && ((Not) other).delegate.equals(delegate); } @Override @@ -186,11 +186,11 @@ public String toString() { * Returns a matcher which matches subclasses of the given type (as well as * the given type). */ - public static Matcher subclassesOf(final Class superclass) { + public static Matcher> subclassesOf(final Class superclass) { return new SubclassesOf(superclass); } - private static class SubclassesOf extends AbstractMatcher { + private static class SubclassesOf extends AbstractMatcher> { private final Class superclass; SubclassesOf(Class superclass) { @@ -198,7 +198,7 @@ private static class SubclassesOf extends AbstractMatcher { } @Override - public boolean matches(Class subclass) { + public boolean matches(Class subclass) { return superclass.isAssignableFrom(subclass); } @@ -295,11 +295,11 @@ public String toString() { * Returns a matcher which matches classes in the given package. Packages are specific to their * classloader, so classes with the same package name may not have the same package at runtime. */ - public static Matcher inPackage(final Package targetPackage) { + public static Matcher> inPackage(final Package targetPackage) { return new InPackage(targetPackage); } - private static class InPackage extends AbstractMatcher { + private static class InPackage extends AbstractMatcher> { private final transient Package targetPackage; private final String packageName; @@ -309,7 +309,7 @@ private static class InPackage extends AbstractMatcher { } @Override - public boolean matches(Class c) { + public boolean matches(Class c) { return c.getPackage().equals(targetPackage); } @@ -342,11 +342,11 @@ public Object readResolve() { * * @since 2.0 */ - public static Matcher inSubpackage(final String targetPackageName) { + public static Matcher> inSubpackage(final String targetPackageName) { return new InSubpackage(targetPackageName); } - private static class InSubpackage extends AbstractMatcher { + private static class InSubpackage extends AbstractMatcher> { private final String targetPackageName; InSubpackage(String targetPackageName) { @@ -354,7 +354,7 @@ private static class InSubpackage extends AbstractMatcher { } @Override - public boolean matches(Class c) { + public boolean matches(Class c) { String classPackageName = c.getPackage().getName(); return classPackageName.equals(targetPackageName) || classPackageName.startsWith(targetPackageName + "."); diff --git a/server/src/main/java/org/elasticsearch/common/lucene/search/function/WeightFactorFunction.java b/server/src/main/java/org/elasticsearch/common/lucene/search/function/WeightFactorFunction.java index 222e934d96a73..40c8896aaabeb 100644 --- a/server/src/main/java/org/elasticsearch/common/lucene/search/function/WeightFactorFunction.java +++ b/server/src/main/java/org/elasticsearch/common/lucene/search/function/WeightFactorFunction.java @@ -49,7 +49,7 @@ public double score(int docId, float subQueryScore) throws IOException { public Explanation explainScore(int docId, Explanation subQueryScore) throws IOException { Explanation functionExplanation = leafFunction.explainScore(docId, subQueryScore); return Explanation.match( - functionExplanation.getValue().floatValue() * (float) getWeight(), "product of:", + functionExplanation.getValue().floatValue() * getWeight(), "product of:", functionExplanation, explainWeight()); } }; diff --git a/server/src/main/java/org/elasticsearch/common/util/ArrayUtils.java b/server/src/main/java/org/elasticsearch/common/util/ArrayUtils.java index 239fb7522e5f7..fe0bda7c74e95 100644 --- a/server/src/main/java/org/elasticsearch/common/util/ArrayUtils.java +++ b/server/src/main/java/org/elasticsearch/common/util/ArrayUtils.java @@ -68,6 +68,7 @@ public static String[] concat(String[] one, String[] other) { * Concatenates 2 arrays */ public static T[] concat(T[] one, T[] other, Class clazz) { + @SuppressWarnings("unchecked") T[] target = (T[]) Array.newInstance(clazz, one.length + other.length); System.arraycopy(one, 0, target, 0, one.length); System.arraycopy(other, 0, target, one.length, other.length); diff --git a/server/src/main/java/org/elasticsearch/common/util/concurrent/EsAbortPolicy.java b/server/src/main/java/org/elasticsearch/common/util/concurrent/EsAbortPolicy.java index 7dcd681ac27ce..d770e5547b604 100644 --- a/server/src/main/java/org/elasticsearch/common/util/concurrent/EsAbortPolicy.java +++ b/server/src/main/java/org/elasticsearch/common/util/concurrent/EsAbortPolicy.java @@ -25,7 +25,7 @@ public void rejectedExecution(Runnable r, ThreadPoolExecutor executor) { throw new IllegalStateException("forced execution, but expected a size queue"); } try { - ((SizeBlockingQueue) queue).forcePut(r); + ((SizeBlockingQueue) queue).forcePut(r); } catch (InterruptedException e) { Thread.currentThread().interrupt(); throw new IllegalStateException("forced execution, but got interrupted", e); diff --git a/server/src/main/java/org/elasticsearch/common/util/concurrent/PrioritizedCallable.java b/server/src/main/java/org/elasticsearch/common/util/concurrent/PrioritizedCallable.java index 28e31306e126a..75fecae571040 100644 --- a/server/src/main/java/org/elasticsearch/common/util/concurrent/PrioritizedCallable.java +++ b/server/src/main/java/org/elasticsearch/common/util/concurrent/PrioritizedCallable.java @@ -11,7 +11,7 @@ import java.util.concurrent.Callable; -public abstract class PrioritizedCallable implements Callable, Comparable { +public abstract class PrioritizedCallable implements Callable, Comparable> { private final Priority priority; @@ -24,7 +24,7 @@ protected PrioritizedCallable(Priority priority) { } @Override - public int compareTo(PrioritizedCallable pc) { + public int compareTo(PrioritizedCallable pc) { return priority.compareTo(pc.priority); } diff --git a/server/src/main/java/org/elasticsearch/common/util/concurrent/SizeBlockingQueue.java b/server/src/main/java/org/elasticsearch/common/util/concurrent/SizeBlockingQueue.java index c844f95234b46..760574a013e42 100644 --- a/server/src/main/java/org/elasticsearch/common/util/concurrent/SizeBlockingQueue.java +++ b/server/src/main/java/org/elasticsearch/common/util/concurrent/SizeBlockingQueue.java @@ -185,7 +185,7 @@ public Object[] toArray() { @Override public T[] toArray(T[] a) { - return (T[]) queue.toArray(a); + return queue.toArray(a); } @Override diff --git a/server/src/main/java/org/elasticsearch/index/mapper/AbstractGeometryFieldMapper.java b/server/src/main/java/org/elasticsearch/index/mapper/AbstractGeometryFieldMapper.java index 0a6d70bf7536e..914963c871dd6 100644 --- a/server/src/main/java/org/elasticsearch/index/mapper/AbstractGeometryFieldMapper.java +++ b/server/src/main/java/org/elasticsearch/index/mapper/AbstractGeometryFieldMapper.java @@ -134,6 +134,7 @@ protected AbstractGeometryFieldMapper( } @Override + @SuppressWarnings("unchecked") public AbstractGeometryFieldType fieldType() { return (AbstractGeometryFieldType) mappedFieldType; } diff --git a/server/src/main/java/org/elasticsearch/node/Node.java b/server/src/main/java/org/elasticsearch/node/Node.java index 0038d9e1249d4..4333c147d54ed 100644 --- a/server/src/main/java/org/elasticsearch/node/Node.java +++ b/server/src/main/java/org/elasticsearch/node/Node.java @@ -200,6 +200,7 @@ import java.util.stream.Stream; import static java.util.stream.Collectors.toList; +import static org.elasticsearch.core.Types.forciblyCast; /** * A node represent a node within a cluster ({@code cluster.name}). The {@link #client()} can be used @@ -1290,9 +1291,4 @@ DiscoveryNode getNode() { return localNode.get(); } } - - @SuppressWarnings("unchecked") - private static T forciblyCast(Object argument) { - return (T) argument; - } } diff --git a/server/src/main/java/org/elasticsearch/search/SearchModule.java b/server/src/main/java/org/elasticsearch/search/SearchModule.java index 316a43105198f..334fea63ff027 100644 --- a/server/src/main/java/org/elasticsearch/search/SearchModule.java +++ b/server/src/main/java/org/elasticsearch/search/SearchModule.java @@ -975,7 +975,7 @@ private void registerQuery(QuerySpec spec) { (p, c) -> spec.getParser().fromXContent(p))); } - private void registerBoolQuery(ParseField name, Writeable.Reader reader) { + private void registerBoolQuery(ParseField name, Writeable.Reader reader) { namedWriteables.add(new NamedWriteableRegistry.Entry(QueryBuilder.class, name.getPreferredName(), reader)); namedXContents.add(new NamedXContentRegistry.Entry(QueryBuilder.class, name, (p, c) -> BoolQueryBuilder.fromXContent(p, (Integer) c))); diff --git a/server/src/main/java/org/elasticsearch/search/aggregations/ParsedMultiBucketAggregation.java b/server/src/main/java/org/elasticsearch/search/aggregations/ParsedMultiBucketAggregation.java index b8c9372692125..3b3f42cc3255e 100644 --- a/server/src/main/java/org/elasticsearch/search/aggregations/ParsedMultiBucketAggregation.java +++ b/server/src/main/java/org/elasticsearch/search/aggregations/ParsedMultiBucketAggregation.java @@ -47,9 +47,11 @@ protected XContentBuilder doXContentBody(XContentBuilder builder, Params params) return builder; } - protected static void declareMultiBucketAggregationFields(final ObjectParser objectParser, - final CheckedFunction bucketParser, - final CheckedFunction keyedBucketParser) { + protected static , T extends ParsedBucket> void declareMultiBucketAggregationFields( + final ObjectParser objectParser, + final CheckedFunction bucketParser, + final CheckedFunction keyedBucketParser + ) { declareAggregationFields(objectParser); objectParser.declareField((parser, aggregation, context) -> { XContentParser.Token token = parser.currentToken(); diff --git a/server/src/main/java/org/elasticsearch/search/aggregations/bucket/composite/BinaryValuesSource.java b/server/src/main/java/org/elasticsearch/search/aggregations/bucket/composite/BinaryValuesSource.java index 262b4b7cebd0c..1a079717477cb 100644 --- a/server/src/main/java/org/elasticsearch/search/aggregations/bucket/composite/BinaryValuesSource.java +++ b/server/src/main/java/org/elasticsearch/search/aggregations/bucket/composite/BinaryValuesSource.java @@ -14,10 +14,10 @@ import org.apache.lucene.search.Query; import org.apache.lucene.util.BytesRef; import org.apache.lucene.util.BytesRefBuilder; -import org.elasticsearch.core.CheckedFunction; -import org.elasticsearch.core.Releasables; import org.elasticsearch.common.util.BigArrays; import org.elasticsearch.common.util.ObjectArray; +import org.elasticsearch.core.CheckedFunction; +import org.elasticsearch.core.Releasables; import org.elasticsearch.index.fielddata.SortedBinaryDocValues; import org.elasticsearch.index.mapper.MappedFieldType; import org.elasticsearch.index.mapper.StringFieldType; @@ -126,7 +126,7 @@ int compareValues(BytesRef v1, BytesRef v2) { } @Override - void setAfter(Comparable value) { + void setAfter(Comparable value) { if (missingBucket && value == null) { afterValue = null; } else if (value.getClass() == String.class) { @@ -162,7 +162,7 @@ public void collect(int doc, long bucket) throws IOException { } @Override - LeafBucketCollector getLeafCollector(Comparable value, LeafReaderContext context, LeafBucketCollector next) { + LeafBucketCollector getLeafCollector(Comparable value, LeafReaderContext context, LeafBucketCollector next) { if (value.getClass() != BytesRef.class) { throw new IllegalArgumentException("Expected BytesRef, got " + value.getClass()); } diff --git a/server/src/main/java/org/elasticsearch/search/aggregations/bucket/composite/CompositeAggregationBuilder.java b/server/src/main/java/org/elasticsearch/search/aggregations/bucket/composite/CompositeAggregationBuilder.java index 4d68ee950850e..c619a91a0b133 100644 --- a/server/src/main/java/org/elasticsearch/search/aggregations/bucket/composite/CompositeAggregationBuilder.java +++ b/server/src/main/java/org/elasticsearch/search/aggregations/bucket/composite/CompositeAggregationBuilder.java @@ -214,7 +214,8 @@ protected AggregatorFactory doBuild(AggregationContext context, AggregatorFactor throw new IllegalArgumentException("[after] has " + after.size() + " value(s) but [sources] has " + sources.size()); } - Comparable[] values = new Comparable[sources.size()]; + @SuppressWarnings("rawtypes") + Comparable[] values = new Comparable[sources.size()]; for (int i = 0; i < sources.size(); i++) { String sourceName = sources.get(i).name(); if (after.containsKey(sourceName) == false) { @@ -224,7 +225,7 @@ protected AggregatorFactory doBuild(AggregationContext context, AggregatorFactor if (configs[i].missingBucket() && obj == null) { values[i] = null; } else if (obj instanceof Comparable) { - values[i] = (Comparable) obj; + values[i] = (Comparable) obj; } else { throw new IllegalArgumentException("Invalid value for [after." + sources.get(i).name() + "], expected comparable, got [" + (obj == null ? "null" : obj.getClass().getSimpleName()) + "]"); diff --git a/server/src/main/java/org/elasticsearch/search/aggregations/bucket/composite/CompositeAggregator.java b/server/src/main/java/org/elasticsearch/search/aggregations/bucket/composite/CompositeAggregator.java index ddc9f8bfa47e6..a9eef47d3d1da 100644 --- a/server/src/main/java/org/elasticsearch/search/aggregations/bucket/composite/CompositeAggregator.java +++ b/server/src/main/java/org/elasticsearch/search/aggregations/bucket/composite/CompositeAggregator.java @@ -87,7 +87,7 @@ final class CompositeAggregator extends BucketsAggregator { this.sourceNames = Arrays.stream(sourceConfigs).map(CompositeValuesSourceConfig::name).collect(Collectors.toList()); this.reverseMuls = Arrays.stream(sourceConfigs).mapToInt(CompositeValuesSourceConfig::reverseMul).toArray(); this.formats = Arrays.stream(sourceConfigs).map(CompositeValuesSourceConfig::format).collect(Collectors.toList()); - this.sources = new SingleDimensionValuesSource[sourceConfigs.length]; + this.sources = new SingleDimensionValuesSource[sourceConfigs.length]; // check that the provided size is not greater than the search.max_buckets setting int bucketLimit = context.multiBucketConsumer().getLimit(); if (size > bucketLimit) { diff --git a/server/src/main/java/org/elasticsearch/search/aggregations/bucket/composite/CompositeKey.java b/server/src/main/java/org/elasticsearch/search/aggregations/bucket/composite/CompositeKey.java index 82a052a58c3f2..f43a8d237a7fc 100644 --- a/server/src/main/java/org/elasticsearch/search/aggregations/bucket/composite/CompositeKey.java +++ b/server/src/main/java/org/elasticsearch/search/aggregations/bucket/composite/CompositeKey.java @@ -18,6 +18,7 @@ /** * A key that is composed of multiple {@link Comparable} values. */ +@SuppressWarnings("rawtypes") class CompositeKey implements Writeable { private final Comparable[] values; diff --git a/server/src/main/java/org/elasticsearch/search/aggregations/bucket/composite/CompositeValuesCollectorQueue.java b/server/src/main/java/org/elasticsearch/search/aggregations/bucket/composite/CompositeValuesCollectorQueue.java index 2deecff822808..00de32979f6f2 100644 --- a/server/src/main/java/org/elasticsearch/search/aggregations/bucket/composite/CompositeValuesCollectorQueue.java +++ b/server/src/main/java/org/elasticsearch/search/aggregations/bucket/composite/CompositeValuesCollectorQueue.java @@ -18,10 +18,12 @@ import org.elasticsearch.search.aggregations.LeafBucketCollector; import java.io.IOException; +import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; -import java.util.stream.Collectors; + +import static org.elasticsearch.core.Types.forciblyCast; /** * A specialized {@link PriorityQueue} implementation for composite buckets. @@ -114,14 +116,14 @@ Integer compareCurrent() { /** * Returns the lowest value (exclusive) of the leading source. */ - Comparable getLowerValueLeadSource() { + Comparable getLowerValueLeadSource() { return afterKeyIsSet ? arrays[0].getAfter() : null; } /** * Returns the upper value (inclusive) of the leading source. */ - Comparable getUpperValueLeadSource() throws IOException { + Comparable getUpperValueLeadSource() throws IOException { return size() >= maxSize ? arrays[0].toComparable(top()) : null; } /** @@ -209,7 +211,7 @@ private int compareCurrentWithAfter() { */ CompositeKey toCompositeKey(int slot) throws IOException { assert slot < maxSize; - Comparable[] values = new Comparable[arrays.length]; + Comparable[] values = new Comparable[arrays.length]; for (int i = 0; i < values.length; i++) { values[i] = arrays[i].toComparable(slot); } @@ -229,7 +231,7 @@ LeafBucketCollector getLeafCollector(LeafReaderContext context, LeafBucketCollec * for each document. * The provided collector in is called on each composite bucket. */ - LeafBucketCollector getLeafCollector(Comparable forceLeadSourceValue, + LeafBucketCollector getLeafCollector(Comparable forceLeadSourceValue, LeafReaderContext context, LeafBucketCollector in) throws IOException { int last = arrays.length - 1; LeafBucketCollector collector = in; @@ -242,13 +244,13 @@ LeafBucketCollector getLeafCollector(Comparable forceLeadSourceValue, SingleDimensionValuesSource valuesSource = arrays[last]; requiresRehashingWhenSwitchingLeafReaders |= valuesSource.requiresRehashingWhenSwitchingLeafReaders(); if (forceLeadSourceValue != null) { - collector = valuesSource.getLeafCollector(forceLeadSourceValue, context, collector); + collector = valuesSource.getLeafCollector(forciblyCast(forceLeadSourceValue), context, collector); } else { collector = valuesSource.getLeafCollector(context, collector); } boolean switchedLeafReaders = context.ord != leafReaderOrd; if (map.isEmpty() == false && requiresRehashingWhenSwitchingLeafReaders && switchedLeafReaders) { - List> entries = map.entrySet().stream().collect(Collectors.toList()); + List> entries = new ArrayList<>(map.entrySet()); map.clear(); entries.forEach(e -> map.put(e.getKey(), e.getValue())); } diff --git a/server/src/main/java/org/elasticsearch/search/aggregations/bucket/composite/CompositeValuesSourceBuilder.java b/server/src/main/java/org/elasticsearch/search/aggregations/bucket/composite/CompositeValuesSourceBuilder.java index 0db590d8d3b35..b3d205c18483c 100644 --- a/server/src/main/java/org/elasticsearch/search/aggregations/bucket/composite/CompositeValuesSourceBuilder.java +++ b/server/src/main/java/org/elasticsearch/search/aggregations/bucket/composite/CompositeValuesSourceBuilder.java @@ -259,6 +259,7 @@ public SortOrder order() { /** * Sets the format to use for the output of the aggregation. */ + @SuppressWarnings("unchecked") public AB format(String format) { if (format == null) { throw new IllegalArgumentException("[format] must not be null: [" + name + "]"); diff --git a/server/src/main/java/org/elasticsearch/search/aggregations/bucket/composite/DateHistogramValuesSourceBuilder.java b/server/src/main/java/org/elasticsearch/search/aggregations/bucket/composite/DateHistogramValuesSourceBuilder.java index 93a97cbf3fb39..19207540108f9 100644 --- a/server/src/main/java/org/elasticsearch/search/aggregations/bucket/composite/DateHistogramValuesSourceBuilder.java +++ b/server/src/main/java/org/elasticsearch/search/aggregations/bucket/composite/DateHistogramValuesSourceBuilder.java @@ -45,8 +45,10 @@ * A {@link CompositeValuesSourceBuilder} that builds a {@link RoundingValuesSource} from a {@link Script} or * a field name using the provided interval. */ -public class DateHistogramValuesSourceBuilder - extends CompositeValuesSourceBuilder implements DateIntervalConsumer { +public class DateHistogramValuesSourceBuilder extends CompositeValuesSourceBuilder + implements + DateIntervalConsumer { + @FunctionalInterface public interface DateHistogramCompositeSupplier { CompositeValuesSourceConfig apply( diff --git a/server/src/main/java/org/elasticsearch/search/aggregations/bucket/composite/DoubleValuesSource.java b/server/src/main/java/org/elasticsearch/search/aggregations/bucket/composite/DoubleValuesSource.java index 45539f914ccd8..9dc915f02641f 100644 --- a/server/src/main/java/org/elasticsearch/search/aggregations/bucket/composite/DoubleValuesSource.java +++ b/server/src/main/java/org/elasticsearch/search/aggregations/bucket/composite/DoubleValuesSource.java @@ -11,11 +11,11 @@ import org.apache.lucene.index.IndexReader; import org.apache.lucene.index.LeafReaderContext; import org.apache.lucene.search.Query; -import org.elasticsearch.core.CheckedFunction; -import org.elasticsearch.core.Releasables; import org.elasticsearch.common.util.BigArrays; import org.elasticsearch.common.util.BitArray; import org.elasticsearch.common.util.DoubleArray; +import org.elasticsearch.core.CheckedFunction; +import org.elasticsearch.core.Releasables; import org.elasticsearch.index.fielddata.SortedNumericDoubleValues; import org.elasticsearch.index.mapper.MappedFieldType; import org.elasticsearch.search.DocValueFormat; @@ -115,7 +115,7 @@ private int compareValues(double v1, double v2) { } @Override - void setAfter(Comparable value) { + void setAfter(Comparable value) { if (missingBucket && value == null) { afterValue = null; } else if (value instanceof Number) { @@ -158,7 +158,7 @@ public void collect(int doc, long bucket) throws IOException { } @Override - LeafBucketCollector getLeafCollector(Comparable value, LeafReaderContext context, LeafBucketCollector next) { + LeafBucketCollector getLeafCollector(Comparable value, LeafReaderContext context, LeafBucketCollector next) { if (value.getClass() != Double.class) { throw new IllegalArgumentException("Expected Double, got " + value.getClass()); } diff --git a/server/src/main/java/org/elasticsearch/search/aggregations/bucket/composite/GeoTileGridValuesSourceBuilder.java b/server/src/main/java/org/elasticsearch/search/aggregations/bucket/composite/GeoTileGridValuesSourceBuilder.java index 0c58dd948c361..4e70153101295 100644 --- a/server/src/main/java/org/elasticsearch/search/aggregations/bucket/composite/GeoTileGridValuesSourceBuilder.java +++ b/server/src/main/java/org/elasticsearch/search/aggregations/bucket/composite/GeoTileGridValuesSourceBuilder.java @@ -52,7 +52,7 @@ CompositeValuesSourceConfig apply( } static final String TYPE = "geotile_grid"; - static final ValuesSourceRegistry.RegistryKey REGISTRY_KEY = new ValuesSourceRegistry.RegistryKey( + static final ValuesSourceRegistry.RegistryKey REGISTRY_KEY = new ValuesSourceRegistry.RegistryKey<>( TYPE, GeoTileCompositeSuppier.class ); diff --git a/server/src/main/java/org/elasticsearch/search/aggregations/bucket/composite/GeoTileValuesSource.java b/server/src/main/java/org/elasticsearch/search/aggregations/bucket/composite/GeoTileValuesSource.java index 11f397f03f718..5bc6b3c16eb3c 100644 --- a/server/src/main/java/org/elasticsearch/search/aggregations/bucket/composite/GeoTileValuesSource.java +++ b/server/src/main/java/org/elasticsearch/search/aggregations/bucket/composite/GeoTileValuesSource.java @@ -37,7 +37,7 @@ class GeoTileValuesSource extends LongValuesSource { } @Override - void setAfter(Comparable value) { + void setAfter(Comparable value) { if (missingBucket && value == null) { afterValue = null; } else if (value instanceof Number) { diff --git a/server/src/main/java/org/elasticsearch/search/aggregations/bucket/composite/InternalComposite.java b/server/src/main/java/org/elasticsearch/search/aggregations/bucket/composite/InternalComposite.java index 87fcf1b19bdcb..5de58fe16b201 100644 --- a/server/src/main/java/org/elasticsearch/search/aggregations/bucket/composite/InternalComposite.java +++ b/server/src/main/java/org/elasticsearch/search/aggregations/bucket/composite/InternalComposite.java @@ -461,10 +461,10 @@ static Object formatObject(Object obj, DocValueFormat format) { static class ArrayMap extends AbstractMap implements Comparable { final List keys; - final Comparable[] values; + final Comparable[] values; final List formats; - ArrayMap(List keys, List formats, Comparable[] values) { + ArrayMap(List keys, List formats, Comparable[] values) { assert keys.size() == values.length && keys.size() == formats.size(); this.keys = keys; this.formats = formats; @@ -516,6 +516,7 @@ public int size() { } @Override + @SuppressWarnings({"rawtypes", "unchecked"}) public int compareTo(ArrayMap that) { if (that == this) { return 0; @@ -526,7 +527,7 @@ public int compareTo(ArrayMap that) { while (idx < max) { int compare = compareNullables(keys.get(idx), that.keys.get(idx)); if (compare == 0) { - compare = compareNullables(values[idx], that.values[idx]); + compare = compareNullables((Comparable) values[idx], (Comparable) that.values[idx]); } if (compare != 0) { return compare; @@ -543,7 +544,7 @@ public int compareTo(ArrayMap that) { } } - private static int compareNullables(Comparable a, Comparable b) { + private static > int compareNullables(T a, T b) { if (a == b) { return 0; } diff --git a/server/src/main/java/org/elasticsearch/search/aggregations/bucket/composite/LongValuesSource.java b/server/src/main/java/org/elasticsearch/search/aggregations/bucket/composite/LongValuesSource.java index e2f76253a2f95..86eb07367cd9e 100644 --- a/server/src/main/java/org/elasticsearch/search/aggregations/bucket/composite/LongValuesSource.java +++ b/server/src/main/java/org/elasticsearch/search/aggregations/bucket/composite/LongValuesSource.java @@ -20,11 +20,11 @@ import org.apache.lucene.search.MatchAllDocsQuery; import org.apache.lucene.search.PointRangeQuery; import org.apache.lucene.search.Query; -import org.elasticsearch.core.CheckedFunction; -import org.elasticsearch.core.Releasables; import org.elasticsearch.common.util.BigArrays; import org.elasticsearch.common.util.BitArray; import org.elasticsearch.common.util.LongArray; +import org.elasticsearch.core.CheckedFunction; +import org.elasticsearch.core.Releasables; import org.elasticsearch.index.mapper.DateFieldMapper; import org.elasticsearch.index.mapper.MappedFieldType; import org.elasticsearch.index.mapper.NumberFieldMapper; @@ -132,7 +132,7 @@ private int compareValues(long v1, long v2) { } @Override - void setAfter(Comparable value) { + void setAfter(Comparable value) { if (missingBucket && value == null) { afterValue = null; } else { @@ -173,7 +173,7 @@ public void collect(int doc, long bucket) throws IOException { } @Override - LeafBucketCollector getLeafCollector(Comparable value, LeafReaderContext context, LeafBucketCollector next) { + LeafBucketCollector getLeafCollector(Comparable value, LeafReaderContext context, LeafBucketCollector next) { if (value.getClass() != Long.class) { throw new IllegalArgumentException("Expected Long, got " + value.getClass()); } diff --git a/server/src/main/java/org/elasticsearch/search/aggregations/bucket/composite/OrdinalValuesSource.java b/server/src/main/java/org/elasticsearch/search/aggregations/bucket/composite/OrdinalValuesSource.java index 1912828bc26e3..1df67c650a3cf 100644 --- a/server/src/main/java/org/elasticsearch/search/aggregations/bucket/composite/OrdinalValuesSource.java +++ b/server/src/main/java/org/elasticsearch/search/aggregations/bucket/composite/OrdinalValuesSource.java @@ -198,7 +198,7 @@ private int compareInternal(long ord1, long ord2, BytesRef bytesRef1, BytesRef b } @Override - void setAfter(Comparable value) { + void setAfter(Comparable value) { assert invariant(); if (missingBucket && value == null) { afterValue = null; @@ -267,7 +267,8 @@ public void collect(int doc, long bucket) throws IOException { } @Override - LeafBucketCollector getLeafCollector(Comparable value, LeafReaderContext context, LeafBucketCollector next) throws IOException { + LeafBucketCollector getLeafCollector(Comparable value, LeafReaderContext context, LeafBucketCollector next) + throws IOException { final boolean leafReaderContextChanged = context.ord != leafReaderOrd; assert leafReaderContextChanged == false || invariant(); // for performance reasons only check invariant upon change if (value.getClass() != BytesRef.class) { diff --git a/server/src/main/java/org/elasticsearch/search/aggregations/bucket/composite/PointsSortedDocsProducer.java b/server/src/main/java/org/elasticsearch/search/aggregations/bucket/composite/PointsSortedDocsProducer.java index 810f3d7e9fcd4..0430aa6c2772e 100644 --- a/server/src/main/java/org/elasticsearch/search/aggregations/bucket/composite/PointsSortedDocsProducer.java +++ b/server/src/main/java/org/elasticsearch/search/aggregations/bucket/composite/PointsSortedDocsProducer.java @@ -43,7 +43,7 @@ DocIdSet processLeaf(Query query, CompositeValuesCollectorQueue queue, return DocIdSet.EMPTY; } long lowerBucket = Long.MIN_VALUE; - Comparable lowerValue = queue.getLowerValueLeadSource(); + Comparable lowerValue = queue.getLowerValueLeadSource(); if (lowerValue != null) { if (lowerValue.getClass() != Long.class) { throw new IllegalStateException("expected Long, got " + lowerValue.getClass()); @@ -52,7 +52,7 @@ DocIdSet processLeaf(Query query, CompositeValuesCollectorQueue queue, } long upperBucket = Long.MAX_VALUE; - Comparable upperValue = queue.getUpperValueLeadSource(); + Comparable upperValue = queue.getUpperValueLeadSource(); if (upperValue != null) { if (upperValue.getClass() != Long.class) { throw new IllegalStateException("expected Long, got " + upperValue.getClass()); diff --git a/server/src/main/java/org/elasticsearch/search/aggregations/bucket/composite/SingleDimensionValuesSource.java b/server/src/main/java/org/elasticsearch/search/aggregations/bucket/composite/SingleDimensionValuesSource.java index b6553320f206c..a6569a2f930b1 100644 --- a/server/src/main/java/org/elasticsearch/search/aggregations/bucket/composite/SingleDimensionValuesSource.java +++ b/server/src/main/java/org/elasticsearch/search/aggregations/bucket/composite/SingleDimensionValuesSource.java @@ -11,9 +11,9 @@ import org.apache.lucene.index.IndexReader; import org.apache.lucene.index.LeafReaderContext; import org.apache.lucene.search.Query; +import org.elasticsearch.common.util.BigArrays; import org.elasticsearch.core.Nullable; import org.elasticsearch.core.Releasable; -import org.elasticsearch.common.util.BigArrays; import org.elasticsearch.index.mapper.MappedFieldType; import org.elasticsearch.search.DocValueFormat; import org.elasticsearch.search.aggregations.LeafBucketCollector; @@ -100,7 +100,7 @@ abstract class SingleDimensionValuesSource> implements R /** * Sets the after value for this source. Values that compares smaller are filtered. */ - abstract void setAfter(Comparable value); + abstract void setAfter(Comparable value); /** * Returns the after value set for this source. @@ -127,7 +127,7 @@ T getAfter() { * Creates a {@link LeafBucketCollector} that sets the current value for each document to the provided * value and invokes {@link LeafBucketCollector#collect} on the provided next collector. */ - abstract LeafBucketCollector getLeafCollector(Comparable value, + abstract LeafBucketCollector getLeafCollector(Comparable value, LeafReaderContext context, LeafBucketCollector next) throws IOException; /** diff --git a/server/src/main/java/org/elasticsearch/search/aggregations/bucket/composite/SortedDocsProducer.java b/server/src/main/java/org/elasticsearch/search/aggregations/bucket/composite/SortedDocsProducer.java index 551a0869ea6f1..2fc025d60291b 100644 --- a/server/src/main/java/org/elasticsearch/search/aggregations/bucket/composite/SortedDocsProducer.java +++ b/server/src/main/java/org/elasticsearch/search/aggregations/bucket/composite/SortedDocsProducer.java @@ -41,7 +41,7 @@ abstract class SortedDocsProducer { * composite buckets. */ protected boolean processBucket(CompositeValuesCollectorQueue queue, LeafReaderContext context, DocIdSetIterator iterator, - Comparable leadSourceBucket, @Nullable DocIdSetBuilder builder) throws IOException { + Comparable leadSourceBucket, @Nullable DocIdSetBuilder builder) throws IOException { final int[] topCompositeCollected = new int[1]; final boolean[] hasCollected = new boolean[1]; final DocCountProvider docCountProvider = new DocCountProvider(); diff --git a/server/src/main/java/org/elasticsearch/search/aggregations/bucket/geogrid/InternalGeoHashGrid.java b/server/src/main/java/org/elasticsearch/search/aggregations/bucket/geogrid/InternalGeoHashGrid.java index f23046343013f..0a1fa2009f53b 100644 --- a/server/src/main/java/org/elasticsearch/search/aggregations/bucket/geogrid/InternalGeoHashGrid.java +++ b/server/src/main/java/org/elasticsearch/search/aggregations/bucket/geogrid/InternalGeoHashGrid.java @@ -30,7 +30,7 @@ public InternalGeoHashGrid(StreamInput in) throws IOException { } @Override - public InternalGeoGrid create(List buckets) { + public InternalGeoGrid create(List buckets) { return new InternalGeoHashGrid(name, requiredSize, buckets, metadata); } @@ -40,7 +40,12 @@ public InternalGeoGridBucket createBucket(InternalAggregations aggregations, Int } @Override - InternalGeoGrid create(String name, int requiredSize, List buckets, Map metadata) { + InternalGeoGrid create( + String name, + int requiredSize, + List buckets, + Map metadata + ) { return new InternalGeoHashGrid(name, requiredSize, buckets, metadata); } @@ -50,7 +55,7 @@ InternalGeoHashGridBucket createBucket(long hashAsLong, long docCount, InternalA } @Override - Reader getBucketReader() { + Reader getBucketReader() { return InternalGeoHashGridBucket::new; } diff --git a/server/src/main/java/org/elasticsearch/search/aggregations/bucket/geogrid/InternalGeoTileGrid.java b/server/src/main/java/org/elasticsearch/search/aggregations/bucket/geogrid/InternalGeoTileGrid.java index a36696c03e65a..a036e772b1501 100644 --- a/server/src/main/java/org/elasticsearch/search/aggregations/bucket/geogrid/InternalGeoTileGrid.java +++ b/server/src/main/java/org/elasticsearch/search/aggregations/bucket/geogrid/InternalGeoTileGrid.java @@ -30,7 +30,7 @@ public InternalGeoTileGrid(StreamInput in) throws IOException { } @Override - public InternalGeoGrid create(List buckets) { + public InternalGeoGrid create(List buckets) { return new InternalGeoTileGrid(name, requiredSize, buckets, metadata); } @@ -40,7 +40,12 @@ public InternalGeoGridBucket createBucket(InternalAggregations aggregations, Int } @Override - InternalGeoGrid create(String name, int requiredSize, List buckets, Map metadata) { + InternalGeoGrid create( + String name, + int requiredSize, + List buckets, + Map metadata + ) { return new InternalGeoTileGrid(name, requiredSize, buckets, metadata); } @@ -50,7 +55,7 @@ InternalGeoTileGridBucket createBucket(long hashAsLong, long docCount, InternalA } @Override - Reader getBucketReader() { + Reader getBucketReader() { return InternalGeoTileGridBucket::new; } diff --git a/server/src/main/java/org/elasticsearch/search/aggregations/bucket/geogrid/ParsedGeoGrid.java b/server/src/main/java/org/elasticsearch/search/aggregations/bucket/geogrid/ParsedGeoGrid.java index 3009e360030d2..b5f6b80e2a2fb 100644 --- a/server/src/main/java/org/elasticsearch/search/aggregations/bucket/geogrid/ParsedGeoGrid.java +++ b/server/src/main/java/org/elasticsearch/search/aggregations/bucket/geogrid/ParsedGeoGrid.java @@ -25,8 +25,8 @@ public List getBuckets() { } public static ObjectParser createParser(Supplier supplier, - CheckedFunction bucketParser, - CheckedFunction keyedBucketParser) { + CheckedFunction bucketParser, + CheckedFunction keyedBucketParser) { ObjectParser parser = new ObjectParser<>(ParsedGeoGrid.class.getSimpleName(), true, supplier); declareMultiBucketAggregationFields(parser, bucketParser, keyedBucketParser); return parser; diff --git a/server/src/main/java/org/elasticsearch/search/aggregations/bucket/histogram/DateHistogramAggregationBuilder.java b/server/src/main/java/org/elasticsearch/search/aggregations/bucket/histogram/DateHistogramAggregationBuilder.java index 245d22e72642e..2b3463f70c37b 100644 --- a/server/src/main/java/org/elasticsearch/search/aggregations/bucket/histogram/DateHistogramAggregationBuilder.java +++ b/server/src/main/java/org/elasticsearch/search/aggregations/bucket/histogram/DateHistogramAggregationBuilder.java @@ -43,7 +43,7 @@ * A builder for histograms on date fields. */ public class DateHistogramAggregationBuilder extends ValuesSourceAggregationBuilder - implements DateIntervalConsumer { + implements DateIntervalConsumer { public static final String NAME = "date_histogram"; public static final ValuesSourceRegistry.RegistryKey REGISTRY_KEY = diff --git a/server/src/main/java/org/elasticsearch/search/aggregations/bucket/histogram/DateIntervalWrapper.java b/server/src/main/java/org/elasticsearch/search/aggregations/bucket/histogram/DateIntervalWrapper.java index 998df46cd84ed..0c465890af6cb 100644 --- a/server/src/main/java/org/elasticsearch/search/aggregations/bucket/histogram/DateIntervalWrapper.java +++ b/server/src/main/java/org/elasticsearch/search/aggregations/bucket/histogram/DateIntervalWrapper.java @@ -74,7 +74,7 @@ public String value() { private DateHistogramInterval dateHistogramInterval; private IntervalTypeEnum intervalType = IntervalTypeEnum.NONE; - public static void declareIntervalFields(ObjectParser parser) { + public static > void declareIntervalFields(ObjectParser parser) { // NOTE: this field is deprecated and will be removed parser.declareField((wrapper, interval) -> { diff --git a/server/src/main/java/org/elasticsearch/search/aggregations/bucket/histogram/InternalAutoDateHistogram.java b/server/src/main/java/org/elasticsearch/search/aggregations/bucket/histogram/InternalAutoDateHistogram.java index e2afe81f15851..2e7125a14a55b 100644 --- a/server/src/main/java/org/elasticsearch/search/aggregations/bucket/histogram/InternalAutoDateHistogram.java +++ b/server/src/main/java/org/elasticsearch/search/aggregations/bucket/histogram/InternalAutoDateHistogram.java @@ -292,7 +292,7 @@ protected boolean lessThan(IteratorAndCurrent a, IteratorAndCurrent(histogram.buckets.iterator())); } } diff --git a/server/src/main/java/org/elasticsearch/search/aggregations/bucket/histogram/InternalVariableWidthHistogram.java b/server/src/main/java/org/elasticsearch/search/aggregations/bucket/histogram/InternalVariableWidthHistogram.java index f0204f7cc15ca..e701835bcd622 100644 --- a/server/src/main/java/org/elasticsearch/search/aggregations/bucket/histogram/InternalVariableWidthHistogram.java +++ b/server/src/main/java/org/elasticsearch/search/aggregations/bucket/histogram/InternalVariableWidthHistogram.java @@ -336,7 +336,7 @@ protected boolean lessThan(IteratorAndCurrent a, IteratorAndCurrent(histogram.buckets.iterator())); } } diff --git a/server/src/main/java/org/elasticsearch/search/aggregations/bucket/range/AbstractRangeBuilder.java b/server/src/main/java/org/elasticsearch/search/aggregations/bucket/range/AbstractRangeBuilder.java index 34a7d7cb9cc90..314876ce8bd6a 100644 --- a/server/src/main/java/org/elasticsearch/search/aggregations/bucket/range/AbstractRangeBuilder.java +++ b/server/src/main/java/org/elasticsearch/search/aggregations/bucket/range/AbstractRangeBuilder.java @@ -105,6 +105,7 @@ protected void innerWriteTo(StreamOutput out) throws IOException { out.writeBoolean(keyed); } + @SuppressWarnings("unchecked") public AB addRange(R range) { if (range == null) { throw new IllegalArgumentException("[range] must not be null: [" + name + "]"); @@ -117,6 +118,7 @@ public List ranges() { return ranges; } + @SuppressWarnings("unchecked") public AB keyed(boolean keyed) { this.keyed = keyed; return (AB) this; @@ -144,6 +146,7 @@ public int hashCode() { } @Override + @SuppressWarnings("unchecked") public boolean equals(Object obj) { if (this == obj) return true; if (obj == null || getClass() != obj.getClass()) return false; diff --git a/server/src/main/java/org/elasticsearch/search/aggregations/bucket/range/GeoDistanceAggregatorSupplier.java b/server/src/main/java/org/elasticsearch/search/aggregations/bucket/range/GeoDistanceAggregatorSupplier.java index b1b599486666d..905be289849b2 100644 --- a/server/src/main/java/org/elasticsearch/search/aggregations/bucket/range/GeoDistanceAggregatorSupplier.java +++ b/server/src/main/java/org/elasticsearch/search/aggregations/bucket/range/GeoDistanceAggregatorSupplier.java @@ -29,7 +29,7 @@ Aggregator build( DistanceUnit units, ValuesSource valuesSource, DocValueFormat format, - InternalRange.Factory rangeFactory, + @SuppressWarnings("rawtypes") InternalRange.Factory rangeFactory, RangeAggregator.Range[] ranges, boolean keyed, AggregationContext context, diff --git a/server/src/main/java/org/elasticsearch/search/aggregations/bucket/range/InternalRange.java b/server/src/main/java/org/elasticsearch/search/aggregations/bucket/range/InternalRange.java index bb33544984793..18c78ecd8cd37 100644 --- a/server/src/main/java/org/elasticsearch/search/aggregations/bucket/range/InternalRange.java +++ b/server/src/main/java/org/elasticsearch/search/aggregations/bucket/range/InternalRange.java @@ -27,6 +27,7 @@ public class InternalRange> extends InternalMultiBucketAggregation implements Range { + @SuppressWarnings("rawtypes") static final Factory FACTORY = new Factory(); public static class Bucket extends InternalMultiBucketAggregation.InternalBucket implements Range.Bucket { @@ -106,6 +107,7 @@ public InternalAggregations getAggregations() { return aggregations; } + @SuppressWarnings("unchecked") protected Factory getFactory() { return FACTORY; } @@ -261,6 +263,7 @@ public List getBuckets() { return ranges; } + @SuppressWarnings("unchecked") public Factory getFactory() { return FACTORY; } @@ -280,6 +283,7 @@ public B createBucket(InternalAggregations aggregations, B prototype) { @Override public InternalAggregation reduce(List aggregations, ReduceContext reduceContext) { reduceContext.consumeBucketsAndMaybeBreak(ranges.size()); + @SuppressWarnings("rawtypes") List[] rangeList = new List[ranges.size()]; for (int i = 0; i < rangeList.length; ++i) { rangeList[i] = new ArrayList<>(); @@ -294,7 +298,7 @@ public InternalAggregation reduce(List aggregations, Reduce final List ranges = new ArrayList<>(); for (int i = 0; i < this.ranges.size(); ++i) { - ranges.add((B) reduceBucket(rangeList[i], reduceContext)); + ranges.add(reduceBucket(rangeList[i], reduceContext)); } return getFactory().create(name, ranges, format, keyed, getMetadata()); } diff --git a/server/src/main/java/org/elasticsearch/search/aggregations/bucket/range/RangeAggregator.java b/server/src/main/java/org/elasticsearch/search/aggregations/bucket/range/RangeAggregator.java index 779cdc3a12669..6d49793bc4d4a 100644 --- a/server/src/main/java/org/elasticsearch/search/aggregations/bucket/range/RangeAggregator.java +++ b/server/src/main/java/org/elasticsearch/search/aggregations/bucket/range/RangeAggregator.java @@ -434,6 +434,7 @@ public static Aggregator buildWithoutAttemptedToAdaptToFilters( private final DocValueFormat format; protected final Range[] ranges; private final boolean keyed; + @SuppressWarnings("rawtypes") private final InternalRange.Factory rangeFactory; private final double averageDocsPerRange; @@ -442,6 +443,7 @@ public RangeAggregator( AggregatorFactories factories, ValuesSource valuesSource, DocValueFormat format, + @SuppressWarnings("rawtypes") InternalRange.Factory rangeFactory, Range[] ranges, double averageDocsPerRange, @@ -474,6 +476,7 @@ protected long subBucketOrdinal(long owningBucketOrdinal, int rangeOrd) { } @Override + @SuppressWarnings("unchecked") public InternalAggregation[] buildAggregations(long[] owningBucketOrds) throws IOException { return buildAggregationsForFixedBucketCount(owningBucketOrds, ranges.length, (offsetInOwningOrd, docCount, subAggregationResults) -> { @@ -483,6 +486,7 @@ public InternalAggregation[] buildAggregations(long[] owningBucketOrds) throws I } @Override + @SuppressWarnings("unchecked") public InternalAggregation buildEmptyAggregation() { InternalAggregations subAggs = buildEmptySubAggregations(); List buckets = new ArrayList<>(ranges.length); @@ -507,6 +511,7 @@ public static class Unmapped extends NonCollect private final R[] ranges; private final boolean keyed; + @SuppressWarnings("rawtypes") private final InternalRange.Factory factory; private final DocValueFormat format; @@ -518,6 +523,7 @@ public Unmapped( DocValueFormat format, AggregationContext context, Aggregator parent, + @SuppressWarnings("rawtypes") InternalRange.Factory factory, Map metadata ) throws IOException { @@ -529,6 +535,7 @@ public Unmapped( } @Override + @SuppressWarnings("unchecked") public InternalAggregation buildEmptyAggregation() { InternalAggregations subAggs = buildEmptySubAggregations(); List buckets = new ArrayList<>(ranges.length); @@ -599,6 +606,7 @@ static class NoOverlap extends NumericRangeAggregator { AggregatorFactories factories, Numeric valuesSource, DocValueFormat format, + @SuppressWarnings("rawtypes") Factory rangeFactory, Range[] ranges, double averageDocsPerRange, @@ -776,7 +784,7 @@ protected InternalAggregation adapt(InternalAggregation delegateResult) { r.getFrom(), r.getTo(), b.getDocCount(), - (InternalAggregations) b.getAggregations(), + b.getAggregations(), keyed, format ) diff --git a/server/src/main/java/org/elasticsearch/search/aggregations/bucket/terms/InternalMappedSignificantTerms.java b/server/src/main/java/org/elasticsearch/search/aggregations/bucket/terms/InternalMappedSignificantTerms.java index 118f6dee63b54..fe0752b7edc72 100644 --- a/server/src/main/java/org/elasticsearch/search/aggregations/bucket/terms/InternalMappedSignificantTerms.java +++ b/server/src/main/java/org/elasticsearch/search/aggregations/bucket/terms/InternalMappedSignificantTerms.java @@ -121,7 +121,7 @@ public XContentBuilder doXContentBody(XContentBuilder builder, Params params) th builder.field(CommonFields.DOC_COUNT.getPreferredName(), subsetSize); builder.field(BG_COUNT, supersetSize); builder.startArray(CommonFields.BUCKETS.getPreferredName()); - for (Bucket bucket : buckets) { + for (Bucket bucket : buckets) { //There is a condition (presumably when only one shard has a bucket?) where reduce is not called // and I end up with buckets that contravene the user's min_doc_count criteria in my reducer if (bucket.subsetDf >= minDocCount) { diff --git a/server/src/main/java/org/elasticsearch/search/aggregations/bucket/terms/InternalRareTerms.java b/server/src/main/java/org/elasticsearch/search/aggregations/bucket/terms/InternalRareTerms.java index c97c0b97dc222..9023e9cd3e7b8 100644 --- a/server/src/main/java/org/elasticsearch/search/aggregations/bucket/terms/InternalRareTerms.java +++ b/server/src/main/java/org/elasticsearch/search/aggregations/bucket/terms/InternalRareTerms.java @@ -183,9 +183,9 @@ public int hashCode() { } protected static XContentBuilder doXContentCommon(XContentBuilder builder, Params params, - List buckets) throws IOException { + List> buckets) throws IOException { builder.startArray(CommonFields.BUCKETS.getPreferredName()); - for (Bucket bucket : buckets) { + for (Bucket bucket : buckets) { bucket.toXContent(builder, params); } builder.endArray(); diff --git a/server/src/main/java/org/elasticsearch/search/aggregations/bucket/terms/ParsedRareTerms.java b/server/src/main/java/org/elasticsearch/search/aggregations/bucket/terms/ParsedRareTerms.java index e76a78d95260c..898d4c7b9d522 100644 --- a/server/src/main/java/org/elasticsearch/search/aggregations/bucket/terms/ParsedRareTerms.java +++ b/server/src/main/java/org/elasticsearch/search/aggregations/bucket/terms/ParsedRareTerms.java @@ -9,11 +9,11 @@ package org.elasticsearch.search.aggregations.bucket.terms; import org.elasticsearch.common.CheckedBiConsumer; -import org.elasticsearch.core.CheckedFunction; import org.elasticsearch.common.xcontent.ObjectParser; import org.elasticsearch.common.xcontent.XContentBuilder; import org.elasticsearch.common.xcontent.XContentParser; import org.elasticsearch.common.xcontent.XContentParserUtils; +import org.elasticsearch.core.CheckedFunction; import org.elasticsearch.search.aggregations.Aggregation; import org.elasticsearch.search.aggregations.Aggregations; import org.elasticsearch.search.aggregations.ParsedMultiBucketAggregation; @@ -51,7 +51,7 @@ protected XContentBuilder doXContentBody(XContentBuilder builder, Params params) static void declareParsedTermsFields(final ObjectParser objectParser, final CheckedFunction bucketParser) { - declareMultiBucketAggregationFields(objectParser, bucketParser::apply, bucketParser::apply); + declareMultiBucketAggregationFields(objectParser, bucketParser, bucketParser); } public abstract static class ParsedBucket extends ParsedMultiBucketAggregation.ParsedBucket implements RareTerms.Bucket { diff --git a/server/src/main/java/org/elasticsearch/search/aggregations/bucket/terms/ParsedSignificantTerms.java b/server/src/main/java/org/elasticsearch/search/aggregations/bucket/terms/ParsedSignificantTerms.java index 33bf22c7e0c2a..059a4f65b73df 100644 --- a/server/src/main/java/org/elasticsearch/search/aggregations/bucket/terms/ParsedSignificantTerms.java +++ b/server/src/main/java/org/elasticsearch/search/aggregations/bucket/terms/ParsedSignificantTerms.java @@ -9,13 +9,13 @@ package org.elasticsearch.search.aggregations.bucket.terms; import org.elasticsearch.common.CheckedBiConsumer; -import org.elasticsearch.core.CheckedFunction; import org.elasticsearch.common.CheckedSupplier; -import org.elasticsearch.common.xcontent.ParseField; import org.elasticsearch.common.xcontent.ObjectParser; +import org.elasticsearch.common.xcontent.ParseField; import org.elasticsearch.common.xcontent.XContentBuilder; import org.elasticsearch.common.xcontent.XContentParser; import org.elasticsearch.common.xcontent.XContentParserUtils; +import org.elasticsearch.core.CheckedFunction; import org.elasticsearch.search.aggregations.Aggregation; import org.elasticsearch.search.aggregations.Aggregations; import org.elasticsearch.search.aggregations.ParsedMultiBucketAggregation; @@ -84,9 +84,11 @@ static T parseSignificantTermsXContent(final return aggregation; } - static void declareParsedSignificantTermsFields(final ObjectParser objectParser, - final CheckedFunction bucketParser) { - declareMultiBucketAggregationFields(objectParser, bucketParser::apply, bucketParser::apply); + static void declareParsedSignificantTermsFields( + final ObjectParser objectParser, + final CheckedFunction bucketParser + ) { + declareMultiBucketAggregationFields(objectParser, bucketParser, bucketParser); objectParser.declareLong((parsedTerms, value) -> parsedTerms.subsetSize = value , CommonFields.DOC_COUNT); objectParser.declareLong((parsedTerms, value) -> parsedTerms.supersetSize = value , new ParseField(InternalMappedSignificantTerms.BG_COUNT)); diff --git a/server/src/main/java/org/elasticsearch/search/aggregations/bucket/terms/ParsedTerms.java b/server/src/main/java/org/elasticsearch/search/aggregations/bucket/terms/ParsedTerms.java index 7584598845ddd..d258fb0fada58 100644 --- a/server/src/main/java/org/elasticsearch/search/aggregations/bucket/terms/ParsedTerms.java +++ b/server/src/main/java/org/elasticsearch/search/aggregations/bucket/terms/ParsedTerms.java @@ -70,7 +70,7 @@ protected XContentBuilder doXContentBody(XContentBuilder builder, Params params) static void declareParsedTermsFields(final ObjectParser objectParser, final CheckedFunction bucketParser) { - declareMultiBucketAggregationFields(objectParser, bucketParser::apply, bucketParser::apply); + declareMultiBucketAggregationFields(objectParser, bucketParser, bucketParser); objectParser.declareLong((parsedTerms, value) -> parsedTerms.docCountErrorUpperBound = value , DOC_COUNT_ERROR_UPPER_BOUND_FIELD_NAME); objectParser.declareLong((parsedTerms, value) -> parsedTerms.sumOtherDocCount = value, diff --git a/server/src/main/java/org/elasticsearch/search/aggregations/pipeline/BucketScriptPipelineAggregator.java b/server/src/main/java/org/elasticsearch/search/aggregations/pipeline/BucketScriptPipelineAggregator.java index 2411009af68c4..231407dfed1b8 100644 --- a/server/src/main/java/org/elasticsearch/search/aggregations/pipeline/BucketScriptPipelineAggregator.java +++ b/server/src/main/java/org/elasticsearch/search/aggregations/pipeline/BucketScriptPipelineAggregator.java @@ -71,6 +71,7 @@ public String getWriteableName() { @Override public InternalAggregation reduce(InternalAggregation aggregation, ReduceContext reduceContext) { + @SuppressWarnings({"rawtypes", "unchecked"}) InternalMultiBucketAggregation originalAgg = (InternalMultiBucketAggregation) aggregation; List buckets = originalAgg.getBuckets(); diff --git a/server/src/main/java/org/elasticsearch/search/aggregations/pipeline/BucketSortPipelineAggregationBuilder.java b/server/src/main/java/org/elasticsearch/search/aggregations/pipeline/BucketSortPipelineAggregationBuilder.java index c3db696fe9f62..df6630601b30a 100644 --- a/server/src/main/java/org/elasticsearch/search/aggregations/pipeline/BucketSortPipelineAggregationBuilder.java +++ b/server/src/main/java/org/elasticsearch/search/aggregations/pipeline/BucketSortPipelineAggregationBuilder.java @@ -43,6 +43,7 @@ public class BucketSortPipelineAggregationBuilder extends AbstractPipelineAggreg private static final ParseField FROM = new ParseField("from"); private static final ParseField SIZE = new ParseField("size"); + @SuppressWarnings("unchecked") public static final ConstructingObjectParser PARSER = new ConstructingObjectParser<>(NAME, false, (a, context) -> new BucketSortPipelineAggregationBuilder(context, (List) a[0])); diff --git a/server/src/main/java/org/elasticsearch/search/aggregations/pipeline/BucketSortPipelineAggregator.java b/server/src/main/java/org/elasticsearch/search/aggregations/pipeline/BucketSortPipelineAggregator.java index 7ff0fa1429627..932fe1d357ff9 100644 --- a/server/src/main/java/org/elasticsearch/search/aggregations/pipeline/BucketSortPipelineAggregator.java +++ b/server/src/main/java/org/elasticsearch/search/aggregations/pipeline/BucketSortPipelineAggregator.java @@ -67,6 +67,7 @@ public String getWriteableName() { @Override public InternalAggregation reduce(InternalAggregation aggregation, ReduceContext reduceContext) { + @SuppressWarnings({"rawtypes", "unchecked"}) InternalMultiBucketAggregation originalAgg = (InternalMultiBucketAggregation) aggregation; List buckets = originalAgg.getBuckets(); @@ -114,6 +115,7 @@ private ComparableBucket(MultiBucketsAggregation parentAgg, InternalMultiBucketA this.sortValues = resolveAndCacheSortValues(); } + @SuppressWarnings("unchecked") private Map> resolveAndCacheSortValues() { Map> resolved = new HashMap<>(); for (FieldSortBuilder sort : sorts) { diff --git a/server/src/main/java/org/elasticsearch/search/aggregations/pipeline/CumulativeSumPipelineAggregator.java b/server/src/main/java/org/elasticsearch/search/aggregations/pipeline/CumulativeSumPipelineAggregator.java index ba632a7073c10..1121e87d6b50e 100644 --- a/server/src/main/java/org/elasticsearch/search/aggregations/pipeline/CumulativeSumPipelineAggregator.java +++ b/server/src/main/java/org/elasticsearch/search/aggregations/pipeline/CumulativeSumPipelineAggregator.java @@ -57,6 +57,7 @@ public String getWriteableName() { @Override public InternalAggregation reduce(InternalAggregation aggregation, ReduceContext reduceContext) { + @SuppressWarnings("rawtypes") InternalMultiBucketAggregation histo = (InternalMultiBucketAggregation) aggregation; diff --git a/server/src/main/java/org/elasticsearch/search/aggregations/pipeline/DerivativePipelineAggregator.java b/server/src/main/java/org/elasticsearch/search/aggregations/pipeline/DerivativePipelineAggregator.java index 88847494a213a..73f3d9ec4aab9 100644 --- a/server/src/main/java/org/elasticsearch/search/aggregations/pipeline/DerivativePipelineAggregator.java +++ b/server/src/main/java/org/elasticsearch/search/aggregations/pipeline/DerivativePipelineAggregator.java @@ -65,6 +65,7 @@ public String getWriteableName() { @Override public InternalAggregation reduce(InternalAggregation aggregation, ReduceContext reduceContext) { + @SuppressWarnings("rawtypes") InternalMultiBucketAggregation histo = (InternalMultiBucketAggregation) aggregation; diff --git a/server/src/main/java/org/elasticsearch/search/aggregations/pipeline/MovFnPipelineAggregator.java b/server/src/main/java/org/elasticsearch/search/aggregations/pipeline/MovFnPipelineAggregator.java index 561ff5446947d..d53a0be7dd1d6 100644 --- a/server/src/main/java/org/elasticsearch/search/aggregations/pipeline/MovFnPipelineAggregator.java +++ b/server/src/main/java/org/elasticsearch/search/aggregations/pipeline/MovFnPipelineAggregator.java @@ -98,6 +98,7 @@ public String getWriteableName() { @Override public InternalAggregation reduce(InternalAggregation aggregation, InternalAggregation.ReduceContext reduceContext) { + @SuppressWarnings("rawtypes") InternalMultiBucketAggregation histo = (InternalMultiBucketAggregation) aggregation; diff --git a/server/src/main/java/org/elasticsearch/search/aggregations/pipeline/SerialDiffPipelineAggregator.java b/server/src/main/java/org/elasticsearch/search/aggregations/pipeline/SerialDiffPipelineAggregator.java index 6a9928bd714d8..e3a24d84e7ed0 100644 --- a/server/src/main/java/org/elasticsearch/search/aggregations/pipeline/SerialDiffPipelineAggregator.java +++ b/server/src/main/java/org/elasticsearch/search/aggregations/pipeline/SerialDiffPipelineAggregator.java @@ -67,6 +67,7 @@ public String getWriteableName() { @Override public InternalAggregation reduce(InternalAggregation aggregation, ReduceContext reduceContext) { + @SuppressWarnings("rawtypes") InternalMultiBucketAggregation histo = (InternalMultiBucketAggregation) aggregation;