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 4 #76302

Merged
merged 17 commits into from
Aug 11, 2021
Merged
Show file tree
Hide file tree
Changes from 14 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 2 additions & 6 deletions server/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -85,10 +85,6 @@ dependencies {

}

tasks.withType(JavaCompile).configureEach {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🥳

options.compilerArgs << "-Xlint:-cast,-rawtypes,-unchecked"
}

// Until this project is always being formatted with spotless, we need to
// guard against `spotless()` not existing.
try {
Expand Down Expand Up @@ -341,7 +337,7 @@ tasks.named('splitPackagesAudit').configure {
'org.elasticsearch.cli.LoggingAwareMultiCommand',

// these should be temporary, query needs package private access to TermScorer though
'org.apache.lucene.search.XCombinedFieldQuery',
'org.apache.lucene.search.XMultiNormsLeafSimScorer'
'org.apache.lucene.search.XCombinedFieldQuery',
'org.apache.lucene.search.XMultiNormsLeafSimScorer'

}
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,7 @@ public void testDelayedMappingPropagationOnPrimary() throws Exception {
throw new AssertionError(e);
}
assertNotNull(properties);
@SuppressWarnings("unchecked")
Object fieldMapping = ((Map<String, Object>) properties).get("field");
assertNotNull(fieldMapping);
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,12 +100,15 @@ public void testGlobalTemplatesDoNotApply() {
assertThat(mappingsResponse.mappings().size(), is(1));
MappingMetadata mappingMetadata = mappingsResponse.mappings().get("a_hidden_index");
assertNotNull(mappingMetadata);
@SuppressWarnings("unchecked")
Map<String, Object> propertiesMap = (Map<String, Object>) mappingMetadata.getSourceAsMap().get("properties");
assertNotNull(propertiesMap);
assertThat(propertiesMap.size(), is(2));
@SuppressWarnings("unchecked")
Map<String, Object> barMap = (Map<String, Object>) propertiesMap.get("bar");
assertNotNull(barMap);
assertThat(barMap.get("type"), is("text"));
@SuppressWarnings("unchecked")
Map<String, Object> bazMap = (Map<String, Object>) propertiesMap.get("baz");
assertNotNull(bazMap);
assertThat(bazMap.get("type"), is("text"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ private static void assertMappingsHaveField(GetMappingsResponse mappings, String
MappingMetadata indexMappings = mappings.getMappings().get("index");
assertNotNull(indexMappings);
Map<String, Object> typeMappingsMap = indexMappings.getSourceAsMap();
@SuppressWarnings("unchecked")
Map<String, Object> properties = (Map<String, Object>) typeMappingsMap.get("properties");
assertTrue("Could not find [" + field + "] in " + typeMappingsMap.toString(), properties.containsKey(field));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -540,7 +540,8 @@ public void testResolvePath() throws Exception {
nodeNameToNodeId.put(cursor.value.getName(), cursor.key);
}

final GroupShardsIterator shardIterators = state.getRoutingTable().activePrimaryShardsGrouped(new String[]{indexName}, false);
final GroupShardsIterator<ShardIterator> shardIterators = state.getRoutingTable()
.activePrimaryShardsGrouped(new String[] { indexName }, false);
final List<ShardIterator> iterators = iterableAsArrayList(shardIterators);
final ShardRouting shardRouting = iterators.iterator().next().nextOrNull();
assertThat(shardRouting, notNullValue());
Expand Down Expand Up @@ -573,7 +574,8 @@ public void testResolvePath() throws Exception {

private Path getPathToShardData(String indexName, String dirSuffix) {
ClusterState state = client().admin().cluster().prepareState().get().getState();
GroupShardsIterator shardIterators = state.getRoutingTable().activePrimaryShardsGrouped(new String[]{indexName}, false);
GroupShardsIterator<ShardIterator> shardIterators = state.getRoutingTable()
.activePrimaryShardsGrouped(new String[] { indexName }, false);
List<ShardIterator> iterators = iterableAsArrayList(shardIterators);
ShardIterator shardIterator = RandomPicks.randomFrom(random(), iterators);
ShardRouting shardRouting = shardIterator.nextOrNull();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -601,7 +601,7 @@ public void testReplicaCorruption() throws Exception {

private int numShards(String... index) {
ClusterState state = client().admin().cluster().prepareState().get().getState();
GroupShardsIterator shardIterators = state.getRoutingTable().activePrimaryShardsGrouped(index, false);
GroupShardsIterator<?> shardIterators = state.getRoutingTable().activePrimaryShardsGrouped(index, false);
return shardIterators.size();
}

Expand All @@ -627,7 +627,7 @@ private ShardRouting corruptRandomPrimaryFile() throws IOException {
private ShardRouting corruptRandomPrimaryFile(final boolean includePerCommitFiles) throws IOException {
ClusterState state = client().admin().cluster().prepareState().get().getState();
Index test = state.metadata().index("test").getIndex();
GroupShardsIterator shardIterators = state.getRoutingTable().activePrimaryShardsGrouped(new String[]{"test"}, false);
GroupShardsIterator<ShardIterator> shardIterators = state.getRoutingTable().activePrimaryShardsGrouped(new String[]{"test"}, false);
List<ShardIterator> iterators = iterableAsArrayList(shardIterators);
ShardIterator shardIterator = RandomPicks.randomFrom(random(), iterators);
ShardRouting shardRouting = shardIterator.nextOrNull();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ private Set<String> nodeIdsWithIndex(String... indices) {

protected int numAssignedShards(String... indices) {
ClusterState state = client().admin().cluster().prepareState().execute().actionGet().getState();
GroupShardsIterator allAssignedShardsGrouped = state.routingTable().allAssignedShardsGrouped(indices, true);
GroupShardsIterator<?> allAssignedShardsGrouped = state.routingTable().allAssignedShardsGrouped(indices, true);
return allAssignedShardsGrouped.size();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,9 @@ public void testUpdateMappingConcurrently() throws Throwable {
assertThat(response.isAcknowledged(), equalTo(true));
GetMappingsResponse getMappingResponse = client2.admin().indices().prepareGetMappings(indexName).get();
MappingMetadata mappings = getMappingResponse.getMappings().get(indexName);
assertThat(((Map<String, Object>) mappings.getSourceAsMap().get("properties")).keySet(),
@SuppressWarnings("unchecked")
Map<String, Object> properties = (Map<String, Object>) mappings.getSourceAsMap().get("properties");
assertThat(properties.keySet(),
Matchers.hasItem(fieldName));
}
} catch (Exception e) {
Expand Down Expand Up @@ -310,6 +312,7 @@ private void assertMappingOnMaster(final String index, final String... fieldName
assertTrue(mappingSource.containsKey("properties"));

for (String fieldName : fieldNames) {
@SuppressWarnings("unchecked")
Map<String, Object> mappingProperties = (Map<String, Object>) mappingSource.get("properties");
if (fieldName.indexOf('.') != -1) {
fieldName = fieldName.replace(".", ".properties.");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,8 @@ public void testResolveSearchRouting() {
"test3", newSet("0", "1", "2", "tw ", " ltw ", " lw"))));
}

@SafeVarargs
@SuppressWarnings("varargs")
private <T> Set<T> newSet(T... elements) {
return newHashSet(elements);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ public void testOpenContextsAfterRejections() throws Exception {
refresh();

int numSearches = 10;
@SuppressWarnings({"rawtypes", "unchecked"})
Future<SearchResponse>[] responses = new Future[numSearches];
SearchType searchType = randomFrom(SearchType.DEFAULT, SearchType.QUERY_THEN_FETCH, SearchType.DFS_QUERY_THEN_FETCH);
logger.info("search type is {}", searchType);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ private void assertMetadata(Map<String, Object> returnedMetadata) {
Object nestedObject = returnedMetadata.get("complex");
assertNotNull(nestedObject);

@SuppressWarnings("unchecked")
Map<String, Object> nestedMap = (Map<String, Object>)nestedObject;
assertEquals("value", nestedMap.get("nested"));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,10 +86,10 @@ protected Map<String, Function<Map<String, Object>, Object>> pluginScripts() {
aggScript(vars, state -> {
// Lazily populate state.list for tests without an init script
if (state.containsKey("list") == false) {
state.put("list", new ArrayList());
state.put("list", new ArrayList<>());
}

((List) state.get("list")).add(1);
((List<Object>) state.get("list")).add(1);
}));

scripts.put("state[param1] = param2", vars ->
Expand All @@ -100,7 +100,7 @@ protected Map<String, Function<Map<String, Object>, Object>> pluginScripts() {
((Map<String, Object>) vars.get("vars")).put("multiplier", 3);

Map<String, Object> state = (Map<String, Object>) vars.get("state");
state.put("list", new ArrayList());
state.put("list", new ArrayList<>());

return state;
});
Expand All @@ -109,10 +109,10 @@ protected Map<String, Function<Map<String, Object>, Object>> pluginScripts() {
aggScript(vars, state -> {
// Lazily populate state.list for tests without an init script
if (state.containsKey("list") == false) {
state.put("list", new ArrayList());
state.put("list", new ArrayList<>());
}

((List) state.get("list")).add(XContentMapValues.extractValue("vars.multiplier", vars));
((List<Object>) state.get("list")).add(XContentMapValues.extractValue("vars.multiplier", vars));
}));

// Equivalent to:
Expand All @@ -128,12 +128,12 @@ protected Map<String, Function<Map<String, Object>, Object>> pluginScripts() {
// return newaggregation"
//
scripts.put("sum state values as a new aggregation", vars -> {
List newAggregation = new ArrayList();
List<Integer> newAggregation = new ArrayList<>();
Map<String, Object> state = (Map<String, Object>) vars.get("state");
List<?> list = (List<?>) state.get("list");

if (list != null) {
Integer sum = 0;
int sum = 0;
for (Object s : list) {
sum += ((Number) s).intValue();
}
Expand All @@ -142,13 +142,9 @@ protected Map<String, Function<Map<String, Object>, Object>> pluginScripts() {
return newAggregation;
});

scripts.put("no-op aggregation", vars -> {
return (Map<String, Object>) vars.get("state");
});
scripts.put("no-op aggregation", vars -> vars.get("state"));

scripts.put("no-op list aggregation", vars -> {
return (List<List<?>>) vars.get("states");
});
scripts.put("no-op list aggregation", vars -> vars.get("states"));

// Equivalent to:
//
Expand All @@ -165,8 +161,8 @@ protected Map<String, Function<Map<String, Object>, Object>> pluginScripts() {
// return newaggregation"
//
scripts.put("sum all states (lists) values as a new aggregation", vars -> {
List newAggregation = new ArrayList();
Integer sum = 0;
List<Integer> newAggregation = new ArrayList<>();
int sum = 0;

List<List<?>> states = (List<List<?>>) vars.get("states");
for (List<?> list : states) {
Expand All @@ -181,8 +177,8 @@ protected Map<String, Function<Map<String, Object>, Object>> pluginScripts() {
});

scripts.put("sum all states' state.list values as a new aggregation", vars -> {
List newAggregation = new ArrayList();
Integer sum = 0;
List<Integer> newAggregation = new ArrayList<>();
int sum = 0;

List<Map<String, Object>> states = (List<Map<String, Object>>) vars.get("states");

Expand Down Expand Up @@ -218,8 +214,8 @@ protected Map<String, Function<Map<String, Object>, Object>> pluginScripts() {
//
scripts.put("multiplied sum all states (lists) values as a new aggregation", vars -> {
Integer multiplier = (Integer) vars.get("multiplier");
List newAggregation = new ArrayList();
Integer sum = 0;
List<Integer> newAggregation = new ArrayList<>();
int sum = 0;

List<List<?>> states = (List<List<?>>) vars.get("states");
for (List<?> list : states) {
Expand Down Expand Up @@ -253,8 +249,8 @@ protected Map<String, Function<Map<String, Object>, Object>> nonDeterministicPlu
return scripts;
}

@SuppressWarnings("unchecked")
static Map<String, Object> aggScript(Map<String, Object> vars, Consumer<Map<String, Object>> fn) {
@SuppressWarnings("unchecked")
Map<String, Object> aggState = (Map<String, Object>) vars.get("state");
fn.accept(aggState);
return aggState;
Expand Down Expand Up @@ -377,7 +373,7 @@ public void testMap() {
if (map.size() == 1) {
assertThat(map.get("count"), notNullValue());
assertThat(map.get("count"), instanceOf(Number.class));
assertThat(map.get("count"), equalTo((Number) 1));
assertThat(map.get("count"), equalTo(1));
numShardsRun++;
}
}
Expand Down Expand Up @@ -431,7 +427,7 @@ public void testMapWithParams() {
String stringValue = (String) entry.getKey();
assertThat(stringValue, equalTo("12"));
Number numberValue = (Number) entry.getValue();
assertThat(numberValue, equalTo((Number) 1));
assertThat(numberValue, equalTo(1));
numShardsRun++;
}
}
Expand Down Expand Up @@ -476,6 +472,7 @@ public void testInitMutatesParams() {
for (Object object : aggregationList) {
assertThat(object, notNullValue());
assertThat(object, instanceOf(HashMap.class));
@SuppressWarnings("unchecked")
Map<String, Object> map = (Map<String, Object>) object;
assertThat(map, hasKey("list"));
assertThat(map.get("list"), instanceOf(List.class));
Expand All @@ -484,7 +481,7 @@ public void testInitMutatesParams() {
assertThat(o, notNullValue());
assertThat(o, instanceOf(Number.class));
Number numberValue = (Number) o;
assertThat(numberValue, equalTo((Number) 3));
assertThat(numberValue, equalTo(3));
totalCount += numberValue.longValue();
}
}
Expand Down Expand Up @@ -698,8 +695,8 @@ public void testInitMapCombineReduceGetProperty() throws Exception {
assertThat(object, instanceOf(Number.class));
assertThat(((Number) object).longValue(), equalTo(numDocs * 3));
assertThat(((InternalAggregation)global).getProperty("scripted"), sameInstance(scriptedMetricAggregation));
assertThat((List) ((InternalAggregation)global).getProperty("scripted.value"), sameInstance((List) aggregationList));
assertThat((List) ((InternalAggregation)scriptedMetricAggregation).getProperty("value"), sameInstance((List) aggregationList));
assertThat((List) ((InternalAggregation)global).getProperty("scripted.value"), sameInstance(aggregationList));
assertThat((List) ((InternalAggregation)scriptedMetricAggregation).getProperty("value"), sameInstance(aggregationList));
}

public void testMapCombineReduceWithParams() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ public String toString(){
}
}

private void assertValidIterators(Iterator expectedBucketIter, Iterator expectedCountsIter, Iterator expectedValuesIter) {
private void assertValidIterators(Iterator<?> expectedBucketIter, Iterator<?> expectedCountsIter, Iterator<?> expectedValuesIter) {
if (expectedBucketIter.hasNext() == false) {
fail("`expectedBucketIter` iterator ended before `actual` iterator, size mismatch");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,27 +85,28 @@ protected Map<String, Function<Map<String, Object>, Object>> pluginScripts() {
Map<String, Function<Map<String, Object>, Object>> scripts = new HashMap<>();

scripts.put("doc['num1'].value", vars -> {
Map<?, ?> doc = (Map) vars.get("doc");
Map<?, ?> doc = (Map<?, ?>) vars.get("doc");
ScriptDocValues.Doubles num1 = (ScriptDocValues.Doubles) doc.get("num1");
return num1.getValue();
});

scripts.put("doc['num1'].value * factor", vars -> {
Map<?, ?> doc = (Map) vars.get("doc");
Map<?, ?> doc = (Map<?, ?>) vars.get("doc");
ScriptDocValues.Doubles num1 = (ScriptDocValues.Doubles) doc.get("num1");
@SuppressWarnings("unchecked")
Map<String, Object> params = (Map<String, Object>) vars.get("params");
Double factor = (Double) params.get("factor");
return num1.getValue() * factor;
});

scripts.put("doc['date'].date.millis", vars -> {
Map<?, ?> doc = (Map) vars.get("doc");
Map<?, ?> doc = (Map<?, ?>) vars.get("doc");
ScriptDocValues.Dates dates = (ScriptDocValues.Dates) doc.get("date");
return dates.getValue().toInstant().toEpochMilli();
});

scripts.put("doc['date'].date.nanos", vars -> {
Map<?, ?> doc = (Map) vars.get("doc");
Map<?, ?> doc = (Map<?, ?>) vars.get("doc");
ScriptDocValues.Dates dates = (ScriptDocValues.Dates) doc.get("date");
return DateUtils.toLong(dates.getValue().toInstant());
});
Expand Down Expand Up @@ -135,19 +136,19 @@ protected Map<String, Function<Map<String, Object>, Object>> pluginScripts() {
}

static Object fieldsScript(Map<String, Object> vars, String fieldName) {
Map<?, ?> fields = (Map) vars.get("_fields");
Map<?, ?> fields = (Map<?, ?>) vars.get("_fields");
FieldLookup fieldLookup = (FieldLookup) fields.get(fieldName);
return fieldLookup.getValue();
}

@SuppressWarnings("unchecked")
static Object sourceScript(Map<String, Object> vars, String path) {
Map<String, Object> source = (Map) vars.get("_source");
@SuppressWarnings("unchecked")
Map<String, Object> source = (Map<String, Object>) vars.get("_source");
return XContentMapValues.extractValue(path, source);
}

static Object docScript(Map<String, Object> vars, String fieldName) {
Map<?, ?> doc = (Map) vars.get("doc");
Map<?, ?> doc = (Map<?, ?>) vars.get("doc");
ScriptDocValues<?> values = (ScriptDocValues<?>) doc.get(fieldName);
return values;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ public void testExists() throws Exception {
Map<String, Object> barObject = new HashMap<>();
barObject.put("foo", "bar");
barObject.put("bar", singletonMap("bar", "foo"));
@SuppressWarnings("unchecked")
@SuppressWarnings({"rawtypes", "unchecked"})
final Map<String, Object>[] sources = new Map[] {
// simple property
singletonMap("foo", "bar"),
Expand Down
Loading