Skip to content

Commit ba3ceea

Browse files
author
Christoph Büscher
authored
Clean up "unused variable" warnings (#31876)
This change cleans up "unused variable" warnings. There are several cases were we most likely want to suppress the warnings (especially in the client documentation test where the snippets contain many unused variables). In a lot of cases the unused variables can just be deleted though.
1 parent 48c169e commit ba3ceea

File tree

119 files changed

+320
-548
lines changed

Some content is hidden

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

119 files changed

+320
-548
lines changed

client/rest-high-level/src/test/java/org/elasticsearch/client/documentation/CRUDDocumentationIT.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,7 @@
114114
*/
115115
public class CRUDDocumentationIT extends ESRestHighLevelClientTestCase {
116116

117+
@SuppressWarnings("unused")
117118
public void testIndex() throws Exception {
118119
RestHighLevelClient client = highLevelClient();
119120

@@ -278,6 +279,7 @@ public void onFailure(Exception e) {
278279
}
279280
}
280281

282+
@SuppressWarnings("unused")
281283
public void testUpdate() throws Exception {
282284
RestHighLevelClient client = highLevelClient();
283285
{
@@ -546,6 +548,7 @@ public void onFailure(Exception e) {
546548
}
547549
}
548550

551+
@SuppressWarnings("unused")
549552
public void testDelete() throws Exception {
550553
RestHighLevelClient client = highLevelClient();
551554

@@ -665,6 +668,7 @@ public void onFailure(Exception e) {
665668
}
666669
}
667670

671+
@SuppressWarnings("unused")
668672
public void testBulk() throws Exception {
669673
RestHighLevelClient client = highLevelClient();
670674
{
@@ -767,6 +771,7 @@ public void onFailure(Exception e) {
767771
}
768772
}
769773

774+
@SuppressWarnings("unused")
770775
public void testReindex() throws Exception {
771776
RestHighLevelClient client = highLevelClient();
772777
{
@@ -905,6 +910,7 @@ public void onFailure(Exception e) {
905910
}
906911
}
907912

913+
@SuppressWarnings("unused")
908914
public void testReindexRethrottle() throws Exception {
909915
RestHighLevelClient client = highLevelClient();
910916
TaskId taskId = new TaskId("oTUltX4IQMOUUVeiohTt8A:124");
@@ -947,6 +953,7 @@ public void onFailure(Exception e) {
947953
assertTrue(latch.await(30L, TimeUnit.SECONDS));
948954
}
949955

956+
@SuppressWarnings("unused")
950957
public void testUpdateByQuery() throws Exception {
951958
RestHighLevelClient client = highLevelClient();
952959
{
@@ -1066,6 +1073,7 @@ public void onFailure(Exception e) {
10661073
}
10671074
}
10681075

1076+
@SuppressWarnings("unused")
10691077
public void testDeleteByQuery() throws Exception {
10701078
RestHighLevelClient client = highLevelClient();
10711079
{
@@ -1173,6 +1181,7 @@ public void onFailure(Exception e) {
11731181
}
11741182
}
11751183

1184+
@SuppressWarnings("unused")
11761185
public void testGet() throws Exception {
11771186
RestHighLevelClient client = highLevelClient();
11781187
{
@@ -1487,6 +1496,7 @@ public void afterBulk(long executionId, BulkRequest request, Throwable failure)
14871496
}
14881497
}
14891498

1499+
@SuppressWarnings("unused")
14901500
public void testMultiGet() throws Exception {
14911501
RestHighLevelClient client = highLevelClient();
14921502

client/rest-high-level/src/test/java/org/elasticsearch/client/documentation/ClusterClientDocumentationIT.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,7 @@ public void onFailure(Exception e) {
192192
}
193193
}
194194

195+
@SuppressWarnings("unused")
195196
public void testClusterGetSettings() throws IOException {
196197
RestHighLevelClient client = highLevelClient();
197198

@@ -257,6 +258,7 @@ public void onFailure(Exception e) {
257258
assertTrue(latch.await(30L, TimeUnit.SECONDS));
258259
}
259260

261+
@SuppressWarnings("unused")
260262
public void testClusterHealth() throws IOException {
261263
RestHighLevelClient client = highLevelClient();
262264
client.indices().create(new CreateIndexRequest("index"), RequestOptions.DEFAULT);

client/rest-high-level/src/test/java/org/elasticsearch/client/documentation/IndicesClientDocumentationIT.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -706,6 +706,7 @@ public void onFailure(Exception e) {
706706
}
707707
}
708708

709+
@SuppressWarnings("unused")
709710
public void testGetFieldMapping() throws IOException, InterruptedException {
710711
RestHighLevelClient client = highLevelClient();
711712

@@ -891,6 +892,7 @@ public void onFailure(Exception e) {
891892
}
892893
}
893894

895+
@SuppressWarnings("unused")
894896
public void testRefreshIndex() throws Exception {
895897
RestHighLevelClient client = highLevelClient();
896898

@@ -959,6 +961,7 @@ public void onFailure(Exception e) {
959961
}
960962
}
961963

964+
@SuppressWarnings("unused")
962965
public void testFlushIndex() throws Exception {
963966
RestHighLevelClient client = highLevelClient();
964967

@@ -1035,6 +1038,7 @@ public void onFailure(Exception e) {
10351038
}
10361039
}
10371040

1041+
@SuppressWarnings("unused")
10381042
public void testSyncedFlushIndex() throws Exception {
10391043
RestHighLevelClient client = highLevelClient();
10401044

@@ -1308,6 +1312,7 @@ public void onFailure(Exception e) {
13081312
assertTrue(latch.await(30L, TimeUnit.SECONDS));
13091313
}
13101314

1315+
@SuppressWarnings("unused")
13111316
public void testForceMergeIndex() throws Exception {
13121317
RestHighLevelClient client = highLevelClient();
13131318

@@ -1381,6 +1386,7 @@ public void onFailure(Exception e) {
13811386
}
13821387
}
13831388

1389+
@SuppressWarnings("unused")
13841390
public void testClearCache() throws Exception {
13851391
RestHighLevelClient client = highLevelClient();
13861392

@@ -1527,6 +1533,7 @@ public void onFailure(Exception e) {
15271533
}
15281534
}
15291535

1536+
@SuppressWarnings("unused")
15301537
public void testExistsAlias() throws Exception {
15311538
RestHighLevelClient client = highLevelClient();
15321539

@@ -1590,6 +1597,7 @@ public void onFailure(Exception e) {
15901597
}
15911598
}
15921599

1600+
@SuppressWarnings("unused")
15931601
public void testUpdateAliases() throws Exception {
15941602
RestHighLevelClient client = highLevelClient();
15951603

@@ -1915,6 +1923,7 @@ public void onFailure(Exception e) {
19151923
assertTrue(latch.await(30L, TimeUnit.SECONDS));
19161924
}
19171925

1926+
@SuppressWarnings("unused")
19181927
public void testGetAlias() throws Exception {
19191928
RestHighLevelClient client = highLevelClient();
19201929

@@ -1985,6 +1994,7 @@ public void onFailure(Exception e) {
19851994
}
19861995
}
19871996

1997+
@SuppressWarnings("unused")
19881998
public void testIndexPutSettings() throws Exception {
19891999
RestHighLevelClient client = highLevelClient();
19902000

@@ -2315,6 +2325,7 @@ public void onFailure(Exception e) {
23152325
assertTrue(latch.await(30L, TimeUnit.SECONDS));
23162326
}
23172327

2328+
@SuppressWarnings("unused")
23182329
public void testValidateQuery() throws IOException, InterruptedException {
23192330
RestHighLevelClient client = highLevelClient();
23202331

client/rest-high-level/src/test/java/org/elasticsearch/client/documentation/IngestClientDocumentationIT.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,7 @@ public void onFailure(Exception e) {
143143
}
144144
}
145145

146+
@SuppressWarnings("unused")
146147
public void testGetPipeline() throws IOException {
147148
RestHighLevelClient client = highLevelClient();
148149

client/rest-high-level/src/test/java/org/elasticsearch/client/documentation/SearchDocumentationIT.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -413,6 +413,7 @@ public void testSearchRequestSuggestions() throws IOException {
413413
}
414414
}
415415

416+
@SuppressWarnings("unused")
416417
public void testSearchRequestHighlighting() throws IOException {
417418
RestHighLevelClient client = highLevelClient();
418419
{
@@ -831,6 +832,8 @@ public void onFailure(Exception e) {
831832
assertTrue(latch.await(30L, TimeUnit.SECONDS));
832833
}
833834

835+
836+
@SuppressWarnings("unused")
834837
public void testMultiSearchTemplateWithInlineScript() throws Exception {
835838
indexSearchTestData();
836839
RestHighLevelClient client = highLevelClient();

client/rest-high-level/src/test/java/org/elasticsearch/client/documentation/SnapshotClientDocumentationIT.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -577,6 +577,7 @@ public void onFailure(Exception exception) {
577577
}
578578
}
579579

580+
@SuppressWarnings("unused")
580581
public void testSnapshotGetSnapshots() throws IOException {
581582
RestHighLevelClient client = highLevelClient();
582583

client/rest-high-level/src/test/java/org/elasticsearch/client/documentation/StoredScriptsDocumentationIT.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@
6666
*/
6767
public class StoredScriptsDocumentationIT extends ESRestHighLevelClientTestCase {
6868

69+
@SuppressWarnings("unused")
6970
public void testGetStoredScript() throws Exception {
7071
RestHighLevelClient client = highLevelClient();
7172

@@ -128,6 +129,7 @@ public void onFailure(Exception e) {
128129

129130
}
130131

132+
@SuppressWarnings("unused")
131133
public void testDeleteStoredScript() throws Exception {
132134
RestHighLevelClient client = highLevelClient();
133135

client/rest-high-level/src/test/java/org/elasticsearch/client/documentation/TasksClientDocumentationIT.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@
6666
*/
6767
public class TasksClientDocumentationIT extends ESRestHighLevelClientTestCase {
6868

69+
@SuppressWarnings("unused")
6970
public void testListTasks() throws IOException {
7071
RestHighLevelClient client = highLevelClient();
7172
{
@@ -149,6 +150,7 @@ public void onFailure(Exception e) {
149150
}
150151
}
151152

153+
@SuppressWarnings("unused")
152154
public void testCancelTasks() throws IOException {
153155
RestHighLevelClient client = highLevelClient();
154156
{

libs/grok/src/main/java/org/elasticsearch/grok/Grok.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,12 +35,12 @@
3535
import java.io.UncheckedIOException;
3636
import java.nio.charset.StandardCharsets;
3737
import java.util.ArrayList;
38+
import java.util.Collections;
3839
import java.util.HashMap;
3940
import java.util.Iterator;
4041
import java.util.List;
4142
import java.util.Locale;
4243
import java.util.Map;
43-
import java.util.Collections;
4444

4545
public final class Grok {
4646

@@ -184,6 +184,7 @@ public String toRegex(String grokPattern) {
184184
String namedPatternRef = groupMatch(NAME_GROUP, region, grokPattern);
185185
String subName = groupMatch(SUBNAME_GROUP, region, grokPattern);
186186
// TODO(tal): Support definitions
187+
@SuppressWarnings("unused")
187188
String definition = groupMatch(DEFINITION_GROUP, region, grokPattern);
188189
String patternName = groupMatch(PATTERN_GROUP, region, grokPattern);
189190

libs/grok/src/test/java/org/elasticsearch/grok/GrokTests.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -262,8 +262,6 @@ public void testCircularReference() {
262262
}
263263

264264
public void testBooleanCaptures() {
265-
Map<String, String> bank = new HashMap<>();
266-
267265
String pattern = "%{WORD:name}=%{WORD:status:boolean}";
268266
Grok g = new Grok(basePatterns, pattern);
269267

libs/nio/src/test/java/org/elasticsearch/nio/FlushOperationTests.java

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121

2222
import org.elasticsearch.test.ESTestCase;
2323
import org.junit.Before;
24-
import org.mockito.ArgumentCaptor;
2524

2625
import java.io.IOException;
2726
import java.nio.ByteBuffer;
@@ -61,8 +60,6 @@ public void testMultipleFlushesWithCompositeBuffer() throws IOException {
6160
ByteBuffer[] buffers = {ByteBuffer.allocate(10), ByteBuffer.allocate(15), ByteBuffer.allocate(3)};
6261
FlushOperation writeOp = new FlushOperation(buffers, listener);
6362

64-
ArgumentCaptor<ByteBuffer[]> buffersCaptor = ArgumentCaptor.forClass(ByteBuffer[].class);
65-
6663
writeOp.incrementIndex(5);
6764
assertFalse(writeOp.isFullyFlushed());
6865
ByteBuffer[] byteBuffers = writeOp.getBuffersToWrite();

libs/x-content/src/test/java/org/elasticsearch/common/xcontent/ObjectParserTests.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -222,6 +222,7 @@ class TestStruct {
222222
public void testFailOnValueType() throws IOException {
223223
XContentParser parser = createParser(JsonXContent.jsonXContent, "{\"numeric_value\" : false}");
224224
class TestStruct {
225+
@SuppressWarnings("unused")
225226
public String test;
226227
}
227228
ObjectParser<TestStruct, Void> objectParser = new ObjectParser<>("foo");

modules/analysis-common/src/main/java/org/elasticsearch/analysis/common/KeepWordFilterFactory.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ public class KeepWordFilterFactory extends AbstractTokenFilterFactory {
5454
private final CharArraySet keepWords;
5555
private static final String KEEP_WORDS_KEY = "keep_words";
5656
private static final String KEEP_WORDS_PATH_KEY = KEEP_WORDS_KEY + "_path";
57+
@SuppressWarnings("unused")
5758
private static final String KEEP_WORDS_CASE_KEY = KEEP_WORDS_KEY + "_case"; // for javadoc
5859

5960
// unsupported ancient option

modules/analysis-common/src/main/java/org/elasticsearch/analysis/common/StemmerTokenFilterFactory.java

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,6 @@
5353
import org.apache.lucene.analysis.ru.RussianLightStemFilter;
5454
import org.apache.lucene.analysis.snowball.SnowballFilter;
5555
import org.apache.lucene.analysis.sv.SwedishLightStemFilter;
56-
import org.elasticsearch.Version;
5756
import org.elasticsearch.common.Strings;
5857
import org.elasticsearch.common.settings.Settings;
5958
import org.elasticsearch.env.Environment;
@@ -94,8 +93,6 @@ public class StemmerTokenFilterFactory extends AbstractTokenFilterFactory {
9493

9594
@Override
9695
public TokenStream create(TokenStream tokenStream) {
97-
final Version indexVersion = indexSettings.getIndexVersionCreated();
98-
9996
if ("arabic".equalsIgnoreCase(language)) {
10097
return new ArabicStemFilter(tokenStream);
10198
} else if ("armenian".equalsIgnoreCase(language)) {

modules/lang-painless/src/main/java/org/elasticsearch/painless/Locals.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -295,7 +295,6 @@ public static final class Variable {
295295
public final Class<?> clazz;
296296
public final boolean readonly;
297297
private final int slot;
298-
private boolean used;
299298

300299
public Variable(Location location, String name, Class<?> clazz, int slot, boolean readonly) {
301300
this.location = location;

modules/parent-join/src/test/java/org/elasticsearch/join/aggregations/ChildrenIT.java

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ public void setupCluster() throws Exception {
9191
String category = categories[j] = uniqueCategories[catIndex++ % uniqueCategories.length];
9292
Control control = categoryToControl.get(category);
9393
if (control == null) {
94-
categoryToControl.put(category, control = new Control(category));
94+
categoryToControl.put(category, control = new Control());
9595
}
9696
control.articleIds.add(id);
9797
}
@@ -457,14 +457,8 @@ public void testPostCollectAllLeafReaders() throws Exception {
457457
}
458458

459459
private static final class Control {
460-
461-
final String category;
462460
final Set<String> articleIds = new HashSet<>();
463461
final Set<String> commentIds = new HashSet<>();
464462
final Map<String, Set<String>> commenterToCommentId = new HashMap<>();
465-
466-
private Control(String category) {
467-
this.category = category;
468-
}
469463
}
470464
}

modules/reindex/src/test/java/org/elasticsearch/client/documentation/ReindexDocumentationIT.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@
4545

4646
public class ReindexDocumentationIT extends ESIntegTestCase {
4747

48+
@SuppressWarnings("unused")
4849
public void reindex() {
4950
Client client = client();
5051
// tag::reindex1
@@ -55,6 +56,7 @@ public void reindex() {
5556
// end::reindex1
5657
}
5758

59+
@SuppressWarnings("unused")
5860
public void updateByQuery() {
5961
Client client = client();
6062
{
@@ -165,6 +167,7 @@ public void updateByQuery() {
165167
}
166168
}
167169

170+
@SuppressWarnings("unused")
168171
public void deleteByQuery() {
169172
Client client = client();
170173
// tag::delete-by-query-sync

0 commit comments

Comments
 (0)