Skip to content

Commit

Permalink
Clean up "unused variable" warnings (#31876)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
Christoph Büscher authored Sep 26, 2018
1 parent 48c169e commit ba3ceea
Show file tree
Hide file tree
Showing 119 changed files with 320 additions and 548 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@
*/
public class CRUDDocumentationIT extends ESRestHighLevelClientTestCase {

@SuppressWarnings("unused")
public void testIndex() throws Exception {
RestHighLevelClient client = highLevelClient();

Expand Down Expand Up @@ -278,6 +279,7 @@ public void onFailure(Exception e) {
}
}

@SuppressWarnings("unused")
public void testUpdate() throws Exception {
RestHighLevelClient client = highLevelClient();
{
Expand Down Expand Up @@ -546,6 +548,7 @@ public void onFailure(Exception e) {
}
}

@SuppressWarnings("unused")
public void testDelete() throws Exception {
RestHighLevelClient client = highLevelClient();

Expand Down Expand Up @@ -665,6 +668,7 @@ public void onFailure(Exception e) {
}
}

@SuppressWarnings("unused")
public void testBulk() throws Exception {
RestHighLevelClient client = highLevelClient();
{
Expand Down Expand Up @@ -767,6 +771,7 @@ public void onFailure(Exception e) {
}
}

@SuppressWarnings("unused")
public void testReindex() throws Exception {
RestHighLevelClient client = highLevelClient();
{
Expand Down Expand Up @@ -905,6 +910,7 @@ public void onFailure(Exception e) {
}
}

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

@SuppressWarnings("unused")
public void testUpdateByQuery() throws Exception {
RestHighLevelClient client = highLevelClient();
{
Expand Down Expand Up @@ -1066,6 +1073,7 @@ public void onFailure(Exception e) {
}
}

@SuppressWarnings("unused")
public void testDeleteByQuery() throws Exception {
RestHighLevelClient client = highLevelClient();
{
Expand Down Expand Up @@ -1173,6 +1181,7 @@ public void onFailure(Exception e) {
}
}

@SuppressWarnings("unused")
public void testGet() throws Exception {
RestHighLevelClient client = highLevelClient();
{
Expand Down Expand Up @@ -1487,6 +1496,7 @@ public void afterBulk(long executionId, BulkRequest request, Throwable failure)
}
}

@SuppressWarnings("unused")
public void testMultiGet() throws Exception {
RestHighLevelClient client = highLevelClient();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,7 @@ public void onFailure(Exception e) {
}
}

@SuppressWarnings("unused")
public void testClusterGetSettings() throws IOException {
RestHighLevelClient client = highLevelClient();

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

@SuppressWarnings("unused")
public void testClusterHealth() throws IOException {
RestHighLevelClient client = highLevelClient();
client.indices().create(new CreateIndexRequest("index"), RequestOptions.DEFAULT);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -706,6 +706,7 @@ public void onFailure(Exception e) {
}
}

@SuppressWarnings("unused")
public void testGetFieldMapping() throws IOException, InterruptedException {
RestHighLevelClient client = highLevelClient();

Expand Down Expand Up @@ -891,6 +892,7 @@ public void onFailure(Exception e) {
}
}

@SuppressWarnings("unused")
public void testRefreshIndex() throws Exception {
RestHighLevelClient client = highLevelClient();

Expand Down Expand Up @@ -959,6 +961,7 @@ public void onFailure(Exception e) {
}
}

@SuppressWarnings("unused")
public void testFlushIndex() throws Exception {
RestHighLevelClient client = highLevelClient();

Expand Down Expand Up @@ -1035,6 +1038,7 @@ public void onFailure(Exception e) {
}
}

@SuppressWarnings("unused")
public void testSyncedFlushIndex() throws Exception {
RestHighLevelClient client = highLevelClient();

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

@SuppressWarnings("unused")
public void testForceMergeIndex() throws Exception {
RestHighLevelClient client = highLevelClient();

Expand Down Expand Up @@ -1381,6 +1386,7 @@ public void onFailure(Exception e) {
}
}

@SuppressWarnings("unused")
public void testClearCache() throws Exception {
RestHighLevelClient client = highLevelClient();

Expand Down Expand Up @@ -1527,6 +1533,7 @@ public void onFailure(Exception e) {
}
}

@SuppressWarnings("unused")
public void testExistsAlias() throws Exception {
RestHighLevelClient client = highLevelClient();

Expand Down Expand Up @@ -1590,6 +1597,7 @@ public void onFailure(Exception e) {
}
}

@SuppressWarnings("unused")
public void testUpdateAliases() throws Exception {
RestHighLevelClient client = highLevelClient();

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

@SuppressWarnings("unused")
public void testGetAlias() throws Exception {
RestHighLevelClient client = highLevelClient();

Expand Down Expand Up @@ -1985,6 +1994,7 @@ public void onFailure(Exception e) {
}
}

@SuppressWarnings("unused")
public void testIndexPutSettings() throws Exception {
RestHighLevelClient client = highLevelClient();

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

@SuppressWarnings("unused")
public void testValidateQuery() throws IOException, InterruptedException {
RestHighLevelClient client = highLevelClient();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,7 @@ public void onFailure(Exception e) {
}
}

@SuppressWarnings("unused")
public void testGetPipeline() throws IOException {
RestHighLevelClient client = highLevelClient();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -413,6 +413,7 @@ public void testSearchRequestSuggestions() throws IOException {
}
}

@SuppressWarnings("unused")
public void testSearchRequestHighlighting() throws IOException {
RestHighLevelClient client = highLevelClient();
{
Expand Down Expand Up @@ -831,6 +832,8 @@ public void onFailure(Exception e) {
assertTrue(latch.await(30L, TimeUnit.SECONDS));
}


@SuppressWarnings("unused")
public void testMultiSearchTemplateWithInlineScript() throws Exception {
indexSearchTestData();
RestHighLevelClient client = highLevelClient();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -577,6 +577,7 @@ public void onFailure(Exception exception) {
}
}

@SuppressWarnings("unused")
public void testSnapshotGetSnapshots() throws IOException {
RestHighLevelClient client = highLevelClient();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@
*/
public class StoredScriptsDocumentationIT extends ESRestHighLevelClientTestCase {

@SuppressWarnings("unused")
public void testGetStoredScript() throws Exception {
RestHighLevelClient client = highLevelClient();

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

}

@SuppressWarnings("unused")
public void testDeleteStoredScript() throws Exception {
RestHighLevelClient client = highLevelClient();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@
*/
public class TasksClientDocumentationIT extends ESRestHighLevelClientTestCase {

@SuppressWarnings("unused")
public void testListTasks() throws IOException {
RestHighLevelClient client = highLevelClient();
{
Expand Down Expand Up @@ -149,6 +150,7 @@ public void onFailure(Exception e) {
}
}

@SuppressWarnings("unused")
public void testCancelTasks() throws IOException {
RestHighLevelClient client = highLevelClient();
{
Expand Down
3 changes: 2 additions & 1 deletion libs/grok/src/main/java/org/elasticsearch/grok/Grok.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,12 @@
import java.io.UncheckedIOException;
import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.Collections;

public final class Grok {

Expand Down Expand Up @@ -184,6 +184,7 @@ public String toRegex(String grokPattern) {
String namedPatternRef = groupMatch(NAME_GROUP, region, grokPattern);
String subName = groupMatch(SUBNAME_GROUP, region, grokPattern);
// TODO(tal): Support definitions
@SuppressWarnings("unused")
String definition = groupMatch(DEFINITION_GROUP, region, grokPattern);
String patternName = groupMatch(PATTERN_GROUP, region, grokPattern);

Expand Down
2 changes: 0 additions & 2 deletions libs/grok/src/test/java/org/elasticsearch/grok/GrokTests.java
Original file line number Diff line number Diff line change
Expand Up @@ -262,8 +262,6 @@ public void testCircularReference() {
}

public void testBooleanCaptures() {
Map<String, String> bank = new HashMap<>();

String pattern = "%{WORD:name}=%{WORD:status:boolean}";
Grok g = new Grok(basePatterns, pattern);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@

import org.elasticsearch.test.ESTestCase;
import org.junit.Before;
import org.mockito.ArgumentCaptor;

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

ArgumentCaptor<ByteBuffer[]> buffersCaptor = ArgumentCaptor.forClass(ByteBuffer[].class);

writeOp.incrementIndex(5);
assertFalse(writeOp.isFullyFlushed());
ByteBuffer[] byteBuffers = writeOp.getBuffersToWrite();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,7 @@ class TestStruct {
public void testFailOnValueType() throws IOException {
XContentParser parser = createParser(JsonXContent.jsonXContent, "{\"numeric_value\" : false}");
class TestStruct {
@SuppressWarnings("unused")
public String test;
}
ObjectParser<TestStruct, Void> objectParser = new ObjectParser<>("foo");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ public class KeepWordFilterFactory extends AbstractTokenFilterFactory {
private final CharArraySet keepWords;
private static final String KEEP_WORDS_KEY = "keep_words";
private static final String KEEP_WORDS_PATH_KEY = KEEP_WORDS_KEY + "_path";
@SuppressWarnings("unused")
private static final String KEEP_WORDS_CASE_KEY = KEEP_WORDS_KEY + "_case"; // for javadoc

// unsupported ancient option
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@
import org.apache.lucene.analysis.ru.RussianLightStemFilter;
import org.apache.lucene.analysis.snowball.SnowballFilter;
import org.apache.lucene.analysis.sv.SwedishLightStemFilter;
import org.elasticsearch.Version;
import org.elasticsearch.common.Strings;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.env.Environment;
Expand Down Expand Up @@ -94,8 +93,6 @@ public class StemmerTokenFilterFactory extends AbstractTokenFilterFactory {

@Override
public TokenStream create(TokenStream tokenStream) {
final Version indexVersion = indexSettings.getIndexVersionCreated();

if ("arabic".equalsIgnoreCase(language)) {
return new ArabicStemFilter(tokenStream);
} else if ("armenian".equalsIgnoreCase(language)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,6 @@ public static final class Variable {
public final Class<?> clazz;
public final boolean readonly;
private final int slot;
private boolean used;

public Variable(Location location, String name, Class<?> clazz, int slot, boolean readonly) {
this.location = location;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ public void setupCluster() throws Exception {
String category = categories[j] = uniqueCategories[catIndex++ % uniqueCategories.length];
Control control = categoryToControl.get(category);
if (control == null) {
categoryToControl.put(category, control = new Control(category));
categoryToControl.put(category, control = new Control());
}
control.articleIds.add(id);
}
Expand Down Expand Up @@ -457,14 +457,8 @@ public void testPostCollectAllLeafReaders() throws Exception {
}

private static final class Control {

final String category;
final Set<String> articleIds = new HashSet<>();
final Set<String> commentIds = new HashSet<>();
final Map<String, Set<String>> commenterToCommentId = new HashMap<>();

private Control(String category) {
this.category = category;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@

public class ReindexDocumentationIT extends ESIntegTestCase {

@SuppressWarnings("unused")
public void reindex() {
Client client = client();
// tag::reindex1
Expand All @@ -55,6 +56,7 @@ public void reindex() {
// end::reindex1
}

@SuppressWarnings("unused")
public void updateByQuery() {
Client client = client();
{
Expand Down Expand Up @@ -165,6 +167,7 @@ public void updateByQuery() {
}
}

@SuppressWarnings("unused")
public void deleteByQuery() {
Client client = client();
// tag::delete-by-query-sync
Expand Down
Loading

0 comments on commit ba3ceea

Please sign in to comment.