Skip to content

Commit 293648b

Browse files
authored
[#40366] Silence some lint warnings in server project (#48927)
Part of #40366. Silence a number of lint warnings in the :server project, which arise when re-enabling suppressed warnings in server/build.gradle.
1 parent 53b09ab commit 293648b

29 files changed

+103
-52
lines changed

server/src/main/java/org/elasticsearch/cluster/ClusterState.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -216,6 +216,7 @@ public ImmutableOpenMap<String, Custom> getCustoms() {
216216
return this.customs;
217217
}
218218

219+
@SuppressWarnings("unchecked")
219220
public <T extends Custom> T custom(String type) {
220221
return (T) customs.get(type);
221222
}
@@ -366,6 +367,7 @@ public String toString() {
366367
}
367368

368369
@Override
370+
@SuppressWarnings("unchecked")
369371
public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException {
370372
EnumSet<Metric> metrics = Metric.parseString(params.param("metric", "_all"), true);
371373

server/src/main/java/org/elasticsearch/cluster/metadata/MappingMetaData.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,7 @@ public CompressedXContent source() {
118118
/**
119119
* Converts the serialized compressed form of the mappings into a parsed map.
120120
*/
121+
@SuppressWarnings("unchecked")
121122
public Map<String, Object> sourceAsMap() throws ElasticsearchParseException {
122123
Map<String, Object> mapping = XContentHelper.convertToMap(source.compressedReference(), true).v2();
123124
if (mapping.size() == 1 && mapping.containsKey(type())) {

server/src/main/java/org/elasticsearch/common/cache/Cache.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -336,7 +336,8 @@ void eviction() {
336336
}
337337

338338
public static final int NUMBER_OF_SEGMENTS = 256;
339-
@SuppressWarnings("unchecked") private final CacheSegment<K, V>[] segments = new CacheSegment[NUMBER_OF_SEGMENTS];
339+
@SuppressWarnings({"unchecked", "rawtypes"})
340+
private final CacheSegment<K, V>[] segments = new CacheSegment[NUMBER_OF_SEGMENTS];
340341

341342
{
342343
for (int i = 0; i < segments.length; i++) {

server/src/main/java/org/elasticsearch/common/document/DocumentField.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,11 +73,12 @@ public String getName() {
7373
/**
7474
* The first value of the hit.
7575
*/
76+
@SuppressWarnings("unchecked")
7677
public <V> V getValue() {
7778
if (values == null || values.isEmpty()) {
7879
return null;
7980
}
80-
return (V)values.get(0);
81+
return (V) values.get(0);
8182
}
8283

8384
/**

server/src/main/java/org/elasticsearch/common/io/stream/NamedWriteableRegistry.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ public <T extends NamedWriteable> Entry(Class<T> categoryClass, String name, Wri
6363
/**
6464
* Constructs a new registry from the given entries.
6565
*/
66+
@SuppressWarnings("rawtypes")
6667
public NamedWriteableRegistry(List<Entry> entries) {
6768
if (entries.isEmpty()) {
6869
registry = Collections.emptyMap();

server/src/main/java/org/elasticsearch/common/io/stream/StreamInput.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -748,13 +748,12 @@ public final Instant readOptionalInstant() throws IOException {
748748
return present ? readInstant() : null;
749749
}
750750

751-
@SuppressWarnings("unchecked")
752-
private List readArrayList() throws IOException {
751+
private List<Object> readArrayList() throws IOException {
753752
int size = readArraySize();
754753
if (size == 0) {
755754
return Collections.emptyList();
756755
}
757-
List list = new ArrayList(size);
756+
List<Object> list = new ArrayList<>(size);
758757
for (int i = 0; i < size; i++) {
759758
list.add(readGenericValue());
760759
}
@@ -790,7 +789,7 @@ private Map readLinkedHashMap() throws IOException {
790789
if (size9 == 0) {
791790
return Collections.emptyMap();
792791
}
793-
Map map9 = new LinkedHashMap(size9);
792+
Map<String, Object> map9 = new LinkedHashMap<>(size9);
794793
for (int i = 0; i < size9; i++) {
795794
map9.put(readString(), readGenericValue());
796795
}
@@ -802,7 +801,7 @@ private Map readHashMap() throws IOException {
802801
if (size10 == 0) {
803802
return Collections.emptyMap();
804803
}
805-
Map map10 = new HashMap(size10);
804+
Map<String, Object> map10 = new HashMap<>(size10);
806805
for (int i = 0; i < size10; i++) {
807806
map10.put(readString(), readGenericValue());
808807
}
@@ -985,6 +984,7 @@ public <T extends Writeable> T readOptionalWriteable(Writeable.Reader<T> reader)
985984
}
986985
}
987986

987+
@SuppressWarnings("unchecked")
988988
public <T extends Exception> T readException() throws IOException {
989989
if (readBoolean()) {
990990
int key = readVInt();

server/src/main/java/org/elasticsearch/common/lucene/Lucene.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -264,7 +264,7 @@ public static void cleanLuceneIndex(Directory directory) throws IOException {
264264
}
265265

266266
public static void checkSegmentInfoIntegrity(final Directory directory) throws IOException {
267-
new SegmentInfos.FindSegmentsFile(directory) {
267+
new SegmentInfos.FindSegmentsFile<>(directory) {
268268

269269
@Override
270270
protected Object doBody(String segmentFileName) throws IOException {
@@ -345,7 +345,7 @@ public static TopDocsAndMaxScore readTopDocs(StreamInput in) throws IOException
345345
}
346346

347347
public static FieldDoc readFieldDoc(StreamInput in) throws IOException {
348-
Comparable[] cFields = new Comparable[in.readVInt()];
348+
Comparable<?>[] cFields = new Comparable<?>[in.readVInt()];
349349
for (int j = 0; j < cFields.length; j++) {
350350
byte type = in.readByte();
351351
if (type == 0) {
@@ -375,7 +375,7 @@ public static FieldDoc readFieldDoc(StreamInput in) throws IOException {
375375
return new FieldDoc(in.readVInt(), in.readFloat(), cFields);
376376
}
377377

378-
public static Comparable readSortValue(StreamInput in) throws IOException {
378+
public static Comparable<?> readSortValue(StreamInput in) throws IOException {
379379
byte type = in.readByte();
380380
if (type == 0) {
381381
return null;
@@ -484,7 +484,7 @@ public static void writeSortValue(StreamOutput out, Object field) throws IOExcep
484484
if (field == null) {
485485
out.writeByte((byte) 0);
486486
} else {
487-
Class type = field.getClass();
487+
Class<?> type = field.getClass();
488488
if (type == String.class) {
489489
out.writeByte((byte) 1);
490490
out.writeString((String) field);

server/src/main/java/org/elasticsearch/common/settings/AbstractScopedSettings.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -302,6 +302,7 @@ public void apply(Map<String, Tuple<A, B>> values, Settings current, Settings pr
302302
* Note: Only settings registered in {@link SettingsModule} can be changed dynamically.
303303
* </p>
304304
*/
305+
@SuppressWarnings("rawtypes")
305306
public synchronized void addAffixGroupUpdateConsumer(List<Setting.AffixSetting<?>> settings, BiConsumer<String, Settings> consumer) {
306307
List<SettingUpdater> affixUpdaters = new ArrayList<>(settings.size());
307308
for (Setting.AffixSetting<?> setting : settings) {
@@ -503,7 +504,7 @@ void validate(final String key, final Settings settings, final boolean validateD
503504
*/
504505
void validate(
505506
final String key, final Settings settings, final boolean validateDependencies, final boolean validateInternalOrPrivateIndex) {
506-
Setting setting = getRaw(key);
507+
Setting<?> setting = getRaw(key);
507508
if (setting == null) {
508509
LevenshteinDistance ld = new LevenshteinDistance();
509510
List<Tuple<Float, String>> scoredKeys = new ArrayList<>();

server/src/main/java/org/elasticsearch/common/settings/IndexScopedSettings.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,7 @@ public IndexScopedSettings copy(Settings settings, IndexMetaData metaData) {
194194
}
195195

196196
@Override
197-
protected void validateSettingKey(Setting setting) {
197+
protected void validateSettingKey(Setting<?> setting) {
198198
if (setting.getKey().startsWith("index.") == false) {
199199
throw new IllegalArgumentException("illegal settings key: [" + setting.getKey() + "] must start with [index.]");
200200
}

server/src/main/java/org/elasticsearch/common/util/CollectionUtils.java

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,7 @@ public static void ensureNoSelfReferences(Object value, String messageHint) {
152152
}
153153
}
154154

155+
@SuppressWarnings("unchecked")
155156
private static Iterable<?> convert(Object value) {
156157
if (value == null) {
157158
return null;
@@ -267,12 +268,13 @@ public static int sortAndDedup(final BytesRefArray bytes, final int[] indices) {
267268

268269
}
269270

271+
@SuppressWarnings("unchecked")
270272
public static <E> ArrayList<E> iterableAsArrayList(Iterable<? extends E> elements) {
271273
if (elements == null) {
272274
throw new NullPointerException("elements");
273275
}
274276
if (elements instanceof Collection) {
275-
return new ArrayList<>((Collection)elements);
277+
return new ArrayList<>((Collection) elements);
276278
} else {
277279
ArrayList<E> list = new ArrayList<>();
278280
for (E element : elements) {
@@ -282,13 +284,17 @@ public static <E> ArrayList<E> iterableAsArrayList(Iterable<? extends E> element
282284
}
283285
}
284286

287+
@SafeVarargs
288+
@SuppressWarnings("varargs")
285289
public static <E> ArrayList<E> arrayAsArrayList(E... elements) {
286290
if (elements == null) {
287291
throw new NullPointerException("elements");
288292
}
289293
return new ArrayList<>(Arrays.asList(elements));
290294
}
291295

296+
@SafeVarargs
297+
@SuppressWarnings("varargs")
292298
public static <E> ArrayList<E> asArrayList(E first, E... other) {
293299
if (other == null) {
294300
throw new NullPointerException("other");
@@ -299,6 +305,8 @@ public static <E> ArrayList<E> asArrayList(E first, E... other) {
299305
return list;
300306
}
301307

308+
@SafeVarargs
309+
@SuppressWarnings("varargs")
302310
public static<E> ArrayList<E> asArrayList(E first, E second, E... other) {
303311
if (other == null) {
304312
throw new NullPointerException("other");

0 commit comments

Comments
 (0)