Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix compiler warnings in :server - part 2 #75792

Merged
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -118,7 +119,7 @@ protected ShardValidateQueryResponse readShardResponse(StreamInput in) throws IO
}

@Override
protected GroupShardsIterator shards(ClusterState clusterState, ValidateQueryRequest request, String[] concreteIndices) {
protected GroupShardsIterator<ShardIterator> shards(ClusterState clusterState, ValidateQueryRequest request, String[] concreteIndices) {
final String routing;
if (request.allShards()) {
routing = null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -182,14 +182,15 @@ 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;
assert assertInvariants(ItemProcessingState.TRANSLATED);
}

/** returns the request that should be executed on the shard. */
@SuppressWarnings("unchecked")
public <T extends DocWriteRequest<T>> T getRequestToExecute() {
assert assertInvariants(ItemProcessingState.TRANSLATED);
return (T) requestToExecute;
Expand Down Expand Up @@ -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!
Expand All @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -47,8 +46,9 @@ ActionListener<BulkResponse> wrapBulkResponse(ActionListener<Response> 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());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,8 @@ protected class AsyncBroadcastAction {
final GroupShardsIterator<ShardIterator> shardsIts;
final int expectedOps;
final AtomicInteger counterOps = new AtomicInteger();
protected final AtomicReferenceArray shardsResponses;
// ShardResponse or Exception
protected final AtomicReferenceArray<Object> shardsResponses;

protected AsyncBroadcastAction(Task task, Request request, ActionListener<Response> listener) {
this.task = task;
Expand Down Expand Up @@ -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<ShardResponse>(0), clusterState));
} catch (Exception e) {
listener.onFailure(e);
}
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -228,7 +228,7 @@ void onOperation(@Nullable ShardRouting shard, final ShardIterator shardIt, int
}
}

protected AtomicReferenceArray shardsResponses() {
protected AtomicReferenceArray<Object> shardsResponses() {
return shardsResponses;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,7 @@ protected String[] resolveNodes(TasksRequest request, ClusterState clusterState)
}
}

@SuppressWarnings("unchecked")
protected void processTasks(TasksRequest request, Consumer<OperationTask> operation) {
if (request.getTaskId().isSet()) {
// we are only checking one task, we can optimize it
Expand All @@ -173,7 +174,7 @@ protected abstract TasksResponse newResponse(TasksRequest request, List<TaskResp
taskOperationFailures, List<FailedNodeException> failedNodeExceptions);

@SuppressWarnings("unchecked")
protected TasksResponse newResponse(TasksRequest request, AtomicReferenceArray responses) {
protected TasksResponse newResponse(TasksRequest request, AtomicReferenceArray<?> responses) {
List<TaskResponse> tasks = new ArrayList<>();
List<FailedNodeException> failedNodeExceptions = new ArrayList<>();
List<TaskOperationFailure> taskOperationFailures = new ArrayList<>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ public T next() {
};
}

@SafeVarargs
@SuppressWarnings("varargs")
pugnascotia marked this conversation as resolved.
Show resolved Hide resolved
public static <T> Iterator<T> concat(Iterator<? extends T>... iterators) {
if (iterators == null) {
throw new NullPointerException("iterators");
Expand All @@ -49,6 +51,8 @@ static class ConcatenatedIterator<T> implements Iterator<T> {
private final Iterator<? extends T>[] iterators;
private int index = 0;

@SafeVarargs
@SuppressWarnings("varargs")
ConcatenatedIterator(Iterator<? extends T>... iterators) {
if (iterators == null) {
throw new NullPointerException("iterators");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public class GeometryCollectionBuilder extends ShapeBuilder<Shape,
/**
* List of shapes. Package scope for testing.
*/
final List<ShapeBuilder> shapes = new ArrayList<>();
final List<ShapeBuilder<?, ?, ?>> shapes = new ArrayList<>();

/**
* Build and empty GeometryCollectionBuilder.
Expand All @@ -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;
}
Expand Down Expand Up @@ -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);
Expand All @@ -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();
Expand Down Expand Up @@ -164,7 +164,7 @@ public Shape buildS4J() {

List<Shape> shapes = new ArrayList<>(this.shapes.size());

for (ShapeBuilder shape : this.shapes) {
for (ShapeBuilder<?, ?, ?> shape : this.shapes) {
shapes.add(shape.buildS4J());
}

Expand All @@ -182,7 +182,7 @@ public GeometryCollection<Geometry> buildGeometry() {
}
List<Geometry> shapes = new ArrayList<>(this.shapes.size());

for (ShapeBuilder shape : this.shapes) {
for (ShapeBuilder<?, ?, ?> shape : this.shapes) {
shapes.add(shape.buildGeometry());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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 + "]";
}
Expand Down Expand Up @@ -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");
Expand All @@ -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();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,13 @@ public interface ShapeParser {
* if the parsers current token has been <code>null</code>
* @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;
Expand All @@ -65,11 +65,11 @@ static ShapeBuilder parse(XContentParser parser, AbstractGeometryFieldMapper geo
* if the parsers current token has been <code>null</code>
* @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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ class ConstantFactory<T> implements InternalFactory<T> {
}

@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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -152,10 +152,11 @@ public void clearBlacklisted() {
public void makeAllBindingsToEagerSingletons(Injector injector) {
Map<Key<?>, Binding<?>> x = new LinkedHashMap<>();
for (Map.Entry<Key<?>, Binding<?>> entry : this.explicitBindingsMutable.entrySet()) {
Key key = entry.getKey();
@SuppressWarnings("unchecked")
Key<Object> key = (Key<Object>) entry.getKey();
BindingImpl<?> binding = (BindingImpl<?>) entry.getValue();
Object value = binding.getProvider().get();
x.put(key, new InstanceBindingImpl<Object>(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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public Boolean visit(StaticInjectionRequest request) {
}

@Override
public Boolean visit(InjectionRequest request) {
public Boolean visit(InjectionRequest<?> request) {
Set<InjectionPoint> injectionPoints;
try {
injectionPoints = request.getInjectionPoints();
Expand Down
Loading