Skip to content

Commit bd1c513

Browse files
author
Christoph Büscher
authored
Reduce more raw types warnings (#31780)
Similar to #31523.
1 parent ca5822e commit bd1c513

File tree

66 files changed

+304
-301
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

66 files changed

+304
-301
lines changed

modules/ingest-common/src/main/java/org/elasticsearch/ingest/common/ForEachProcessor.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ boolean isIgnoreMissing() {
6363

6464
@Override
6565
public void execute(IngestDocument ingestDocument) throws Exception {
66-
List values = ingestDocument.getFieldValue(field, List.class, ignoreMissing);
66+
List<?> values = ingestDocument.getFieldValue(field, List.class, ignoreMissing);
6767
if (values == null) {
6868
if (ignoreMissing) {
6969
return;

modules/ingest-common/src/main/java/org/elasticsearch/ingest/common/RemoveProcessor.java

+3-1
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,9 @@ public RemoveProcessor create(Map<String, Processor.Factory> registry, String pr
7373
final List<String> fields = new ArrayList<>();
7474
final Object field = ConfigurationUtils.readObject(TYPE, processorTag, config, "field");
7575
if (field instanceof List) {
76-
fields.addAll((List) field);
76+
@SuppressWarnings("unchecked")
77+
List<String> stringList = (List<String>) field;
78+
fields.addAll(stringList);
7779
} else {
7880
fields.add((String) field);
7981
}

modules/ingest-common/src/main/java/org/elasticsearch/ingest/common/SortProcessor.java

+3-2
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ public enum SortOrder {
4949
this.direction = direction;
5050
}
5151

52+
@Override
5253
public String toString() {
5354
return this.direction;
5455
}
@@ -94,13 +95,13 @@ String getTargetField() {
9495
@Override
9596
@SuppressWarnings("unchecked")
9697
public void execute(IngestDocument document) {
97-
List<? extends Comparable> list = document.getFieldValue(field, List.class);
98+
List<? extends Comparable<Object>> list = document.getFieldValue(field, List.class);
9899

99100
if (list == null) {
100101
throw new IllegalArgumentException("field [" + field + "] is null, cannot sort.");
101102
}
102103

103-
List<? extends Comparable> copy = new ArrayList<>(list);
104+
List<? extends Comparable<Object>> copy = new ArrayList<>(list);
104105

105106
if (order.equals(SortOrder.ASCENDING)) {
106107
Collections.sort(copy);

modules/ingest-common/src/test/java/org/elasticsearch/ingest/common/ForEachProcessorTests.java

+17-15
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,6 @@
1919

2020
package org.elasticsearch.ingest.common;
2121

22-
import java.util.ArrayList;
23-
import java.util.Arrays;
24-
import java.util.Collections;
25-
import java.util.HashMap;
26-
import java.util.List;
27-
import java.util.Locale;
28-
import java.util.Map;
2922
import org.elasticsearch.ingest.CompoundProcessor;
3023
import org.elasticsearch.ingest.IngestDocument;
3124
import org.elasticsearch.ingest.Processor;
@@ -34,6 +27,14 @@
3427
import org.elasticsearch.script.TemplateScript;
3528
import org.elasticsearch.test.ESTestCase;
3629

30+
import java.util.ArrayList;
31+
import java.util.Arrays;
32+
import java.util.Collections;
33+
import java.util.HashMap;
34+
import java.util.List;
35+
import java.util.Locale;
36+
import java.util.Map;
37+
3738
import static org.elasticsearch.ingest.IngestDocumentMatcher.assertIngestDocument;
3839
import static org.hamcrest.Matchers.equalTo;
3940

@@ -54,7 +55,8 @@ public void testExecute() throws Exception {
5455
);
5556
processor.execute(ingestDocument);
5657

57-
List result = ingestDocument.getFieldValue("values", List.class);
58+
@SuppressWarnings("unchecked")
59+
List<String> result = ingestDocument.getFieldValue("values", List.class);
5860
assertThat(result.get(0), equalTo("FOO"));
5961
assertThat(result.get(1), equalTo("BAR"));
6062
assertThat(result.get(2), equalTo("BAZ"));
@@ -204,12 +206,12 @@ public void testModifyFieldsOutsideArray() throws Exception {
204206
), false);
205207
processor.execute(ingestDocument);
206208

207-
List result = ingestDocument.getFieldValue("values", List.class);
209+
List<?> result = ingestDocument.getFieldValue("values", List.class);
208210
assertThat(result.get(0), equalTo("STRING"));
209211
assertThat(result.get(1), equalTo(1));
210212
assertThat(result.get(2), equalTo(null));
211213

212-
List errors = ingestDocument.getFieldValue("errors", List.class);
214+
List<?> errors = ingestDocument.getFieldValue("errors", List.class);
213215
assertThat(errors.size(), equalTo(2));
214216
}
215217

@@ -230,7 +232,7 @@ public void testScalarValueAllowsUnderscoreValueFieldToRemainAccessible() throws
230232
ForEachProcessor forEachProcessor = new ForEachProcessor("_tag", "values", processor, false);
231233
forEachProcessor.execute(ingestDocument);
232234

233-
List result = ingestDocument.getFieldValue("values", List.class);
235+
List<?> result = ingestDocument.getFieldValue("values", List.class);
234236
assertThat(result.get(0), equalTo("new_value"));
235237
assertThat(result.get(1), equalTo("new_value"));
236238
assertThat(result.get(2), equalTo("new_value"));
@@ -263,13 +265,13 @@ public void testNestedForEach() throws Exception {
263265
"_tag", "values1", new ForEachProcessor("_tag", "_ingest._value.values2", testProcessor, false), false);
264266
processor.execute(ingestDocument);
265267

266-
List result = ingestDocument.getFieldValue("values1.0.values2", List.class);
268+
List<?> result = ingestDocument.getFieldValue("values1.0.values2", List.class);
267269
assertThat(result.get(0), equalTo("ABC"));
268270
assertThat(result.get(1), equalTo("DEF"));
269271

270-
result = ingestDocument.getFieldValue("values1.1.values2", List.class);
271-
assertThat(result.get(0), equalTo("GHI"));
272-
assertThat(result.get(1), equalTo("JKL"));
272+
List<?> result2 = ingestDocument.getFieldValue("values1.1.values2", List.class);
273+
assertThat(result2.get(0), equalTo("GHI"));
274+
assertThat(result2.get(1), equalTo("JKL"));
273275
}
274276

275277
public void testIgnoreMissing() throws Exception {

modules/ingest-common/src/test/java/org/elasticsearch/ingest/common/IngestRestartIT.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ public static class CustomScriptPlugin extends MockScriptPlugin {
6060
protected Map<String, Function<Map<String, Object>, Object>> pluginScripts() {
6161
return Collections.singletonMap("my_script", script -> {
6262
@SuppressWarnings("unchecked")
63-
Map<String, Object> ctx = (Map) script.get("ctx");
63+
Map<String, Object> ctx = (Map<String, Object>) script.get("ctx");
6464
ctx.put("z", 0);
6565
return null;
6666
});

modules/lang-mustache/src/main/java/org/elasticsearch/script/mustache/CustomMustacheFactory.java

+4-5
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
import com.github.mustachejava.codes.DefaultMustache;
3131
import com.github.mustachejava.codes.IterableCode;
3232
import com.github.mustachejava.codes.WriteCode;
33+
3334
import org.elasticsearch.common.Strings;
3435
import org.elasticsearch.common.xcontent.XContentBuilder;
3536
import org.elasticsearch.common.xcontent.XContentType;
@@ -202,11 +203,9 @@ protected Function<String, String> createFunction(Object resolved) {
202203
return null;
203204
}
204205
try (XContentBuilder builder = XContentBuilder.builder(XContentType.JSON.xContent())) {
205-
if (resolved == null) {
206-
builder.nullValue();
207-
} else if (resolved instanceof Iterable) {
206+
if (resolved instanceof Iterable) {
208207
builder.startArray();
209-
for (Object o : (Iterable) resolved) {
208+
for (Object o : (Iterable<?>) resolved) {
210209
builder.value(o);
211210
}
212211
builder.endArray();
@@ -254,7 +253,7 @@ protected Function<String, String> createFunction(Object resolved) {
254253
return null;
255254
} else if (resolved instanceof Iterable) {
256255
StringJoiner joiner = new StringJoiner(delimiter);
257-
for (Object o : (Iterable) resolved) {
256+
for (Object o : (Iterable<?>) resolved) {
258257
joiner.add(oh.stringify(o));
259258
}
260259
return joiner.toString();

modules/percolator/src/test/java/org/elasticsearch/percolator/PercolatorQuerySearchTests.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ protected Map<String, Function<Map<String, Object>, Object>> pluginScripts() {
6565
scripts.put("1==1", vars -> Boolean.TRUE);
6666
scripts.put("use_fielddata_please", vars -> {
6767
LeafDocLookup leafDocLookup = (LeafDocLookup) vars.get("_doc");
68-
ScriptDocValues scriptDocValues = leafDocLookup.get("employees.name");
68+
ScriptDocValues<?> scriptDocValues = leafDocLookup.get("employees.name");
6969
return "virginia_potts".equals(scriptDocValues.get(0));
7070
});
7171
return scripts;

server/src/main/java/org/apache/lucene/search/uhighlight/CustomUnifiedHighlighter.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@ private Collection<Query> rewriteCustomQuery(Query query) {
173173
SpanQuery[] innerQueries = new SpanQuery[terms[i].length];
174174
for (int j = 0; j < terms[i].length; j++) {
175175
if (i == sizeMinus1) {
176-
innerQueries[j] = new SpanMultiTermQueryWrapper(new PrefixQuery(terms[i][j]));
176+
innerQueries[j] = new SpanMultiTermQueryWrapper<PrefixQuery>(new PrefixQuery(terms[i][j]));
177177
} else {
178178
innerQueries[j] = new SpanTermQuery(terms[i][j]);
179179
}

server/src/main/java/org/elasticsearch/action/DocWriteRequest.java

+4-3
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ public interface DocWriteRequest<T> extends IndicesRequest {
5757
* Get the options for this request
5858
* @return the indices options
5959
*/
60+
@Override
6061
IndicesOptions indicesOptions();
6162

6263
/**
@@ -157,9 +158,9 @@ public static OpType fromString(String sOpType) {
157158
}
158159

159160
/** read a document write (index/delete/update) request */
160-
static DocWriteRequest readDocumentRequest(StreamInput in) throws IOException {
161+
static DocWriteRequest<?> readDocumentRequest(StreamInput in) throws IOException {
161162
byte type = in.readByte();
162-
DocWriteRequest docWriteRequest;
163+
DocWriteRequest<?> docWriteRequest;
163164
if (type == 0) {
164165
IndexRequest indexRequest = new IndexRequest();
165166
indexRequest.readFrom(in);
@@ -179,7 +180,7 @@ static DocWriteRequest readDocumentRequest(StreamInput in) throws IOException {
179180
}
180181

181182
/** write a document write (index/delete/update) request*/
182-
static void writeDocumentRequest(StreamOutput out, DocWriteRequest request) throws IOException {
183+
static void writeDocumentRequest(StreamOutput out, DocWriteRequest<?> request) throws IOException {
183184
if (request instanceof IndexRequest) {
184185
out.writeByte((byte) 0);
185186
((IndexRequest) request).writeTo(out);

server/src/main/java/org/elasticsearch/action/admin/cluster/settings/ClusterUpdateSettingsRequest.java

+2-4
Original file line numberDiff line numberDiff line change
@@ -108,8 +108,7 @@ public ClusterUpdateSettingsRequest transientSettings(String source, XContentTyp
108108
/**
109109
* Sets the transient settings to be updated. They will not survive a full cluster restart
110110
*/
111-
@SuppressWarnings({"unchecked", "rawtypes"})
112-
public ClusterUpdateSettingsRequest transientSettings(Map source) {
111+
public ClusterUpdateSettingsRequest transientSettings(Map<String, ?> source) {
113112
try {
114113
XContentBuilder builder = XContentFactory.contentBuilder(XContentType.JSON);
115114
builder.map(source);
@@ -147,8 +146,7 @@ public ClusterUpdateSettingsRequest persistentSettings(String source, XContentTy
147146
/**
148147
* Sets the persistent settings to be updated. They will get applied cross restarts
149148
*/
150-
@SuppressWarnings({"unchecked", "rawtypes"})
151-
public ClusterUpdateSettingsRequest persistentSettings(Map source) {
149+
public ClusterUpdateSettingsRequest persistentSettings(Map<String, ?> source) {
152150
try {
153151
XContentBuilder builder = XContentFactory.contentBuilder(XContentType.JSON);
154152
builder.map(source);

server/src/main/java/org/elasticsearch/action/admin/cluster/settings/ClusterUpdateSettingsRequestBuilder.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ public ClusterUpdateSettingsRequestBuilder setTransientSettings(String settings,
6262
/**
6363
* Sets the transient settings to be updated. They will not survive a full cluster restart
6464
*/
65-
public ClusterUpdateSettingsRequestBuilder setTransientSettings(Map settings) {
65+
public ClusterUpdateSettingsRequestBuilder setTransientSettings(Map<String, ?> settings) {
6666
request.transientSettings(settings);
6767
return this;
6868
}
@@ -94,7 +94,7 @@ public ClusterUpdateSettingsRequestBuilder setPersistentSettings(String settings
9494
/**
9595
* Sets the persistent settings to be updated. They will get applied cross restarts
9696
*/
97-
public ClusterUpdateSettingsRequestBuilder setPersistentSettings(Map settings) {
97+
public ClusterUpdateSettingsRequestBuilder setPersistentSettings(Map<String, ?> settings) {
9898
request.persistentSettings(settings);
9999
return this;
100100
}

server/src/main/java/org/elasticsearch/action/admin/indices/create/CreateIndexRequest.java

+4-7
Original file line numberDiff line numberDiff line change
@@ -58,9 +58,9 @@
5858
import java.util.Set;
5959

6060
import static org.elasticsearch.action.ValidateActions.addValidationError;
61-
import static org.elasticsearch.common.settings.Settings.Builder.EMPTY_SETTINGS;
6261
import static org.elasticsearch.common.settings.Settings.readSettingsFromStream;
6362
import static org.elasticsearch.common.settings.Settings.writeSettingsToStream;
63+
import static org.elasticsearch.common.settings.Settings.Builder.EMPTY_SETTINGS;
6464

6565
/**
6666
* A request to create an index. Best created with {@link org.elasticsearch.client.Requests#createIndexRequest(String)}.
@@ -189,8 +189,7 @@ public CreateIndexRequest settings(XContentBuilder builder) {
189189
/**
190190
* The settings to create the index with (either json/yaml/properties format)
191191
*/
192-
@SuppressWarnings("unchecked")
193-
public CreateIndexRequest settings(Map source) {
192+
public CreateIndexRequest settings(Map<String, ?> source) {
194193
try {
195194
XContentBuilder builder = XContentFactory.contentBuilder(XContentType.JSON);
196195
builder.map(source);
@@ -256,8 +255,7 @@ public CreateIndexRequest mapping(String type, XContentBuilder source) {
256255
* @param type The mapping type
257256
* @param source The mapping source
258257
*/
259-
@SuppressWarnings("unchecked")
260-
public CreateIndexRequest mapping(String type, Map source) {
258+
public CreateIndexRequest mapping(String type, Map<String, ?> source) {
261259
if (mappings.containsKey(type)) {
262260
throw new IllegalStateException("mappings for type \"" + type + "\" were already defined");
263261
}
@@ -286,8 +284,7 @@ public CreateIndexRequest mapping(String type, Object... source) {
286284
/**
287285
* Sets the aliases that will be associated with the index when it gets created
288286
*/
289-
@SuppressWarnings("unchecked")
290-
public CreateIndexRequest aliases(Map source) {
287+
public CreateIndexRequest aliases(Map<String, ?> source) {
291288
try {
292289
XContentBuilder builder = XContentFactory.jsonBuilder();
293290
builder.map(source);

server/src/main/java/org/elasticsearch/action/admin/indices/create/CreateIndexRequestBuilder.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ public CreateIndexRequestBuilder addMapping(String type, Object... source) {
147147
/**
148148
* Sets the aliases that will be associated with the index when it gets created
149149
*/
150-
public CreateIndexRequestBuilder setAliases(Map source) {
150+
public CreateIndexRequestBuilder setAliases(Map<String, ?> source) {
151151
request.aliases(source);
152152
return this;
153153
}

server/src/main/java/org/elasticsearch/action/admin/indices/flush/TransportShardFlushAction.java

+3-2
Original file line numberDiff line numberDiff line change
@@ -50,10 +50,11 @@ protected ReplicationResponse newResponseInstance() {
5050
}
5151

5252
@Override
53-
protected PrimaryResult shardOperationOnPrimary(ShardFlushRequest shardRequest, IndexShard primary) {
53+
protected PrimaryResult<ShardFlushRequest, ReplicationResponse> shardOperationOnPrimary(ShardFlushRequest shardRequest,
54+
IndexShard primary) {
5455
primary.flush(shardRequest.getRequest());
5556
logger.trace("{} flush request executed on primary", primary.shardId());
56-
return new PrimaryResult(shardRequest, new ReplicationResponse());
57+
return new PrimaryResult<ShardFlushRequest, ReplicationResponse>(shardRequest, new ReplicationResponse());
5758
}
5859

5960
@Override

server/src/main/java/org/elasticsearch/action/admin/indices/mapping/get/GetMappingsResponse.java

+4-5
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,14 @@
2020
package org.elasticsearch.action.admin.indices.mapping.get;
2121

2222
import com.carrotsearch.hppc.cursors.ObjectObjectCursor;
23+
2324
import org.elasticsearch.action.ActionResponse;
2425
import org.elasticsearch.cluster.metadata.MappingMetaData;
2526
import org.elasticsearch.common.ParseField;
2627
import org.elasticsearch.common.Strings;
2728
import org.elasticsearch.common.collect.ImmutableOpenMap;
2829
import org.elasticsearch.common.io.stream.StreamInput;
2930
import org.elasticsearch.common.io.stream.StreamOutput;
30-
import org.elasticsearch.common.xcontent.ObjectParser;
3131
import org.elasticsearch.common.xcontent.ToXContentFragment;
3232
import org.elasticsearch.common.xcontent.XContentBuilder;
3333
import org.elasticsearch.common.xcontent.XContentParser;
@@ -39,9 +39,6 @@ public class GetMappingsResponse extends ActionResponse implements ToXContentFra
3939

4040
private static final ParseField MAPPINGS = new ParseField("mappings");
4141

42-
private static final ObjectParser<GetMappingsResponse, Void> PARSER =
43-
new ObjectParser<GetMappingsResponse, Void>("get-mappings", false, GetMappingsResponse::new);
44-
4542
private ImmutableOpenMap<String, ImmutableOpenMap<String, MappingMetaData>> mappings = ImmutableOpenMap.of();
4643

4744
GetMappingsResponse(ImmutableOpenMap<String, ImmutableOpenMap<String, MappingMetaData>> mappings) {
@@ -101,13 +98,15 @@ public static GetMappingsResponse fromXContent(XContentParser parser) throws IOE
10198
for (Map.Entry<String, Object> entry : parts.entrySet()) {
10299
final String indexName = entry.getKey();
103100
assert entry.getValue() instanceof Map : "expected a map as type mapping, but got: " + entry.getValue().getClass();
104-
final Map<String, Object> mapping = (Map<String, Object>) ((Map) entry.getValue()).get(MAPPINGS.getPreferredName());
101+
@SuppressWarnings("unchecked")
102+
final Map<String, Object> mapping = (Map<String, Object>) ((Map<String, ?>) entry.getValue()).get(MAPPINGS.getPreferredName());
105103

106104
ImmutableOpenMap.Builder<String, MappingMetaData> typeBuilder = new ImmutableOpenMap.Builder<>();
107105
for (Map.Entry<String, Object> typeEntry : mapping.entrySet()) {
108106
final String typeName = typeEntry.getKey();
109107
assert typeEntry.getValue() instanceof Map : "expected a map as inner type mapping, but got: " +
110108
typeEntry.getValue().getClass();
109+
@SuppressWarnings("unchecked")
111110
final Map<String, Object> fieldMappings = (Map<String, Object>) typeEntry.getValue();
112111
MappingMetaData mmd = new MappingMetaData(typeName, fieldMappings);
113112
typeBuilder.put(typeName, mmd);

server/src/main/java/org/elasticsearch/action/admin/indices/mapping/put/PutMappingRequest.java

+1-2
Original file line numberDiff line numberDiff line change
@@ -256,8 +256,7 @@ public PutMappingRequest source(XContentBuilder mappingBuilder) {
256256
/**
257257
* The mapping source definition.
258258
*/
259-
@SuppressWarnings("unchecked")
260-
public PutMappingRequest source(Map mappingSource) {
259+
public PutMappingRequest source(Map<String, ?> mappingSource) {
261260
try {
262261
XContentBuilder builder = XContentFactory.contentBuilder(XContentType.JSON);
263262
builder.map(mappingSource);

server/src/main/java/org/elasticsearch/action/admin/indices/rollover/Condition.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -90,10 +90,10 @@ public Stats(long numDocs, long indexCreated, ByteSizeValue indexSize) {
9090
* Holder for evaluated condition result
9191
*/
9292
public static class Result {
93-
public final Condition condition;
93+
public final Condition<?> condition;
9494
public final boolean matched;
9595

96-
protected Result(Condition condition, boolean matched) {
96+
protected Result(Condition<?> condition, boolean matched) {
9797
this.condition = condition;
9898
this.matched = matched;
9999
}

0 commit comments

Comments
 (0)