Skip to content

Commit

Permalink
Checkstyle shadows vars pt9 (#81296) (#81359)
Browse files Browse the repository at this point in the history
Part of #19752. Fix more instances where local variable names were
shadowing field names.
  • Loading branch information
pugnascotia committed Dec 6, 2021
1 parent 77a65eb commit 81ebcbc
Show file tree
Hide file tree
Showing 86 changed files with 461 additions and 444 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -460,8 +460,8 @@ String taskDescription() {
}

@Override
public Task createTask(long id, String type, String action, TaskId parentTaskId, Map<String, String> headers) {
return new CancellableTask(id, type, action, taskDescription(), parentTaskId, headers);
public Task createTask(long someId, String type, String action, TaskId parentTaskId, Map<String, String> headers) {
return new CancellableTask(someId, type, action, taskDescription(), parentTaskId, headers);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -235,11 +235,11 @@ private Set<String> findNodesWithShard(String index) {
ClusterState state = client().admin().cluster().prepareState().get().getState();
IndexRoutingTable indexRoutingTable = state.routingTable().index(index);
List<ShardRouting> startedShards = indexRoutingTable.shardsWithState(ShardRoutingState.STARTED);
Set<String> nodesWithShard = new HashSet<>();
Set<String> nodesNamesWithShard = new HashSet<>();
for (ShardRouting startedShard : startedShards) {
nodesWithShard.add(state.nodes().get(startedShard.currentNodeId()).getName());
nodesNamesWithShard.add(state.nodes().get(startedShard.currentNodeId()).getName());
}
return nodesWithShard;
return nodesNamesWithShard;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -107,12 +107,12 @@ private void testCase(NodeClient client, SearchRequest request, List<SearchShard
SearchProgressActionListener listener = new SearchProgressActionListener() {
@Override
public void onListShards(
List<SearchShard> shards,
List<SearchShard> searchShards,
List<SearchShard> skippedShards,
SearchResponse.Clusters clusters,
boolean fetchPhase
) {
shardsListener.set(shards);
shardsListener.set(searchShards);
assertEquals(fetchPhase, hasFetchPhase);
}

Expand Down Expand Up @@ -141,12 +141,12 @@ public void onFetchFailure(int shardIndex, SearchShardTarget shardTarget, Except
}

@Override
public void onPartialReduce(List<SearchShard> shards, TotalHits totalHits, InternalAggregations aggs, int reducePhase) {
public void onPartialReduce(List<SearchShard> searchShards, TotalHits totalHits, InternalAggregations aggs, int reducePhase) {
numReduces.incrementAndGet();
}

@Override
public void onFinalReduce(List<SearchShard> shards, TotalHits totalHits, InternalAggregations aggs, int reducePhase) {
public void onFinalReduce(List<SearchShard> searchShards, TotalHits totalHits, InternalAggregations aggs, int reducePhase) {
numReduces.incrementAndGet();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -675,7 +675,7 @@ public Aggregator parent() {
}

@Override
public Aggregator subAggregator(String name) {
public Aggregator subAggregator(String aggregatorName) {
return null;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -278,12 +278,12 @@ public void indexShardStateChanged(
IndexShardState newState,
@Nullable String reason
) {
List<IndexShardState> shardStates = this.shardStates.putIfAbsent(
List<IndexShardState> shardStateList = this.shardStates.putIfAbsent(
indexShard.shardId(),
new CopyOnWriteArrayList<>(new IndexShardState[] { newState })
);
if (shardStates != null) {
shardStates.add(newState);
if (shardStateList != null) {
shardStateList.add(newState);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -449,7 +449,7 @@ public void testParseGeoPoint() throws Exception {
)
.setRefreshPolicy(IMMEDIATE)
.get();
FunctionScoreQueryBuilder baseQuery = functionScoreQuery(
FunctionScoreQueryBuilder baseQueryBuilder = functionScoreQuery(
constantScoreQuery(termQuery("test", "value")),
ScoreFunctionBuilders.weightFactorFunction(randomIntBetween(1, 10))
);
Expand All @@ -458,7 +458,7 @@ public void testParseGeoPoint() throws Exception {
searchRequest().searchType(SearchType.QUERY_THEN_FETCH)
.source(
searchSource().query(
functionScoreQuery(baseQuery, gaussDecayFunction("loc", point, "1000km")).boostMode(CombineFunction.REPLACE)
functionScoreQuery(baseQueryBuilder, gaussDecayFunction("loc", point, "1000km")).boostMode(CombineFunction.REPLACE)
)
)
);
Expand All @@ -473,7 +473,7 @@ public void testParseGeoPoint() throws Exception {
searchRequest().searchType(SearchType.QUERY_THEN_FETCH)
.source(
searchSource().query(
functionScoreQuery(baseQuery, gaussDecayFunction("loc", coords, "1000km")).boostMode(CombineFunction.REPLACE)
functionScoreQuery(baseQueryBuilder, gaussDecayFunction("loc", coords, "1000km")).boostMode(CombineFunction.REPLACE)
)
)
);
Expand Down Expand Up @@ -510,7 +510,7 @@ public void testCombineModes() throws Exception {
.setRefreshPolicy(IMMEDIATE)
.setSource(jsonBuilder().startObject().field("test", "value value").field("num", 1.0).endObject())
.get();
FunctionScoreQueryBuilder baseQuery = functionScoreQuery(
FunctionScoreQueryBuilder baseQueryBuilder = functionScoreQuery(
constantScoreQuery(termQuery("test", "value")),
ScoreFunctionBuilders.weightFactorFunction(2)
);
Expand All @@ -519,7 +519,9 @@ public void testCombineModes() throws Exception {
searchRequest().searchType(SearchType.QUERY_THEN_FETCH)
.source(
searchSource().query(
functionScoreQuery(baseQuery, gaussDecayFunction("num", 0.0, 1.0, null, 0.5)).boostMode(CombineFunction.MULTIPLY)
functionScoreQuery(baseQueryBuilder, gaussDecayFunction("num", 0.0, 1.0, null, 0.5)).boostMode(
CombineFunction.MULTIPLY
)
)
)
);
Expand All @@ -533,7 +535,9 @@ public void testCombineModes() throws Exception {
searchRequest().searchType(SearchType.QUERY_THEN_FETCH)
.source(
searchSource().query(
functionScoreQuery(baseQuery, gaussDecayFunction("num", 0.0, 1.0, null, 0.5)).boostMode(CombineFunction.REPLACE)
functionScoreQuery(baseQueryBuilder, gaussDecayFunction("num", 0.0, 1.0, null, 0.5)).boostMode(
CombineFunction.REPLACE
)
)
)
);
Expand All @@ -547,7 +551,7 @@ public void testCombineModes() throws Exception {
searchRequest().searchType(SearchType.QUERY_THEN_FETCH)
.source(
searchSource().query(
functionScoreQuery(baseQuery, gaussDecayFunction("num", 0.0, 1.0, null, 0.5)).boostMode(CombineFunction.SUM)
functionScoreQuery(baseQueryBuilder, gaussDecayFunction("num", 0.0, 1.0, null, 0.5)).boostMode(CombineFunction.SUM)
)
)
);
Expand All @@ -562,7 +566,7 @@ public void testCombineModes() throws Exception {
searchRequest().searchType(SearchType.QUERY_THEN_FETCH)
.source(
searchSource().query(
functionScoreQuery(baseQuery, gaussDecayFunction("num", 0.0, 1.0, null, 0.5)).boostMode(CombineFunction.AVG)
functionScoreQuery(baseQueryBuilder, gaussDecayFunction("num", 0.0, 1.0, null, 0.5)).boostMode(CombineFunction.AVG)
)
)
);
Expand All @@ -576,7 +580,7 @@ public void testCombineModes() throws Exception {
searchRequest().searchType(SearchType.QUERY_THEN_FETCH)
.source(
searchSource().query(
functionScoreQuery(baseQuery, gaussDecayFunction("num", 0.0, 1.0, null, 0.5)).boostMode(CombineFunction.MIN)
functionScoreQuery(baseQueryBuilder, gaussDecayFunction("num", 0.0, 1.0, null, 0.5)).boostMode(CombineFunction.MIN)
)
)
);
Expand All @@ -590,7 +594,7 @@ public void testCombineModes() throws Exception {
searchRequest().searchType(SearchType.QUERY_THEN_FETCH)
.source(
searchSource().query(
functionScoreQuery(baseQuery, gaussDecayFunction("num", 0.0, 1.0, null, 0.5)).boostMode(CombineFunction.MAX)
functionScoreQuery(baseQueryBuilder, gaussDecayFunction("num", 0.0, 1.0, null, 0.5)).boostMode(CombineFunction.MAX)
)
)
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1023,11 +1023,11 @@ public void testThatSuggestStopFilterWorks() throws Exception {
.put("index.analysis.filter.suggest_stop_filter.type", "stop")
.put("index.analysis.filter.suggest_stop_filter.remove_trailing", false);

CompletionMappingBuilder completionMappingBuilder = new CompletionMappingBuilder();
completionMappingBuilder.preserveSeparators(true).preservePositionIncrements(true);
completionMappingBuilder.searchAnalyzer("stoptest");
completionMappingBuilder.indexAnalyzer("simple");
createIndexAndMappingAndSettings(settingsBuilder.build(), completionMappingBuilder);
CompletionMappingBuilder builder = new CompletionMappingBuilder();
builder.preserveSeparators(true).preservePositionIncrements(true);
builder.searchAnalyzer("stoptest");
builder.indexAnalyzer("simple");
createIndexAndMappingAndSettings(settingsBuilder.build(), builder);

client().prepareIndex(INDEX, TYPE, "1")
.setSource(
Expand Down Expand Up @@ -1071,8 +1071,8 @@ public void testThatSuggestStopFilterWorks() throws Exception {
}

public void testThatIndexingInvalidFieldsInCompletionFieldResultsInException() throws Exception {
CompletionMappingBuilder completionMappingBuilder = new CompletionMappingBuilder();
createIndexAndMapping(completionMappingBuilder);
CompletionMappingBuilder builder = new CompletionMappingBuilder();
createIndexAndMapping(builder);

try {
client().prepareIndex(INDEX, TYPE, "1")
Expand Down Expand Up @@ -1229,7 +1229,7 @@ private static List<String> getNames(Suggest.Suggestion.Entry<Suggest.Suggestion
return names;
}

private void createIndexAndMappingAndSettings(Settings settings, CompletionMappingBuilder completionMappingBuilder) throws IOException {
private void createIndexAndMappingAndSettings(Settings settings, CompletionMappingBuilder builder) throws IOException {
XContentBuilder mapping = jsonBuilder().startObject()
.startObject(TYPE)
.startObject("properties")
Expand All @@ -1241,14 +1241,14 @@ private void createIndexAndMappingAndSettings(Settings settings, CompletionMappi
.endObject()
.startObject(FIELD)
.field("type", "completion")
.field("analyzer", completionMappingBuilder.indexAnalyzer)
.field("search_analyzer", completionMappingBuilder.searchAnalyzer)
.field("preserve_separators", completionMappingBuilder.preserveSeparators)
.field("preserve_position_increments", completionMappingBuilder.preservePositionIncrements);
.field("analyzer", builder.indexAnalyzer)
.field("search_analyzer", builder.searchAnalyzer)
.field("preserve_separators", builder.preserveSeparators)
.field("preserve_position_increments", builder.preservePositionIncrements);

if (completionMappingBuilder.contextMappings != null) {
if (builder.contextMappings != null) {
mapping = mapping.startArray("contexts");
for (Map.Entry<String, ContextMapping<?>> contextMapping : completionMappingBuilder.contextMappings.entrySet()) {
for (Map.Entry<String, ContextMapping<?>> contextMapping : builder.contextMappings.entrySet()) {
mapping = mapping.startObject()
.field("name", contextMapping.getValue().name())
.field("type", contextMapping.getValue().type().name());
Expand Down Expand Up @@ -1279,8 +1279,8 @@ private void createIndexAndMappingAndSettings(Settings settings, CompletionMappi
);
}

private void createIndexAndMapping(CompletionMappingBuilder completionMappingBuilder) throws IOException {
createIndexAndMappingAndSettings(Settings.EMPTY, completionMappingBuilder);
private void createIndexAndMapping(CompletionMappingBuilder builder) throws IOException {
createIndexAndMappingAndSettings(Settings.EMPTY, builder);
}

// see #3555
Expand Down Expand Up @@ -1601,8 +1601,8 @@ public CompletionMappingBuilder preservePositionIncrements(Boolean preservePosit
return this;
}

public CompletionMappingBuilder context(LinkedHashMap<String, ContextMapping<?>> contextMappings) {
this.contextMappings = contextMappings;
public CompletionMappingBuilder context(LinkedHashMap<String, ContextMapping<?>> mappings) {
this.contextMappings = mappings;
return this;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -379,8 +379,10 @@ public Version get() {
}

public void consume(Version version) {
if (version == null) return;
this.current.updateAndGet(current -> version.compareTo(current) <= 0 ? current : version);
if (version == null) {
return;
}
this.current.updateAndGet(currentVersion -> version.compareTo(currentVersion) <= 0 ? currentVersion : version);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -691,8 +691,8 @@ public Builder setPriorSystemIndexDescriptors(List<SystemIndexDescriptor> priorS
return this;
}

public Builder setThreadPools(ExecutorNames executorNames) {
this.executorNames = executorNames;
public Builder setThreadPools(ExecutorNames threadPoolExecutorNames) {
this.executorNames = threadPoolExecutorNames;
return this;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,11 @@ public MockResponse setBody(String body) {
}

/**
* @param statusCode The status code to be returned if the response is sent by the webserver, defaults to 200
* @param responseCode The status code to be returned if the response is sent by the webserver, defaults to 200
* @return The updated mock response
*/
public MockResponse setResponseCode(int statusCode) {
this.statusCode = statusCode;
public MockResponse setResponseCode(int responseCode) {
this.statusCode = responseCode;
return this;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,8 @@ public AsyncExecutionId getExecutionId() {
}

@Override
public void setExpirationTime(long expirationTimeMillis) {
this.expirationTimeMillis = expirationTimeMillis;
public void setExpirationTime(long expirationTime) {
this.expirationTimeMillis = expirationTime;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -214,11 +214,11 @@ public long getLimit() {
return limit;
}

void adjustLimit(long limit) {
if (limit < used) {
throw new IllegalArgumentException("Limit must not be smaller than used; used=" + used + "; limit=" + limit);
void adjustLimit(long newLimit) {
if (newLimit < used) {
throw new IllegalArgumentException("Limit must not be smaller than used; used=" + used + "; limit=" + newLimit);
}
this.limit = limit;
this.limit = newLimit;
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,10 +99,7 @@ public void shutdownThreadPool() {
}

public void testInfo() throws IOException {
AbstractAuditor<AbstractAuditMessageTests.TestAuditMessage> auditor = createTestAuditorWithTemplateInstalled(
client,
Version.CURRENT
);
AbstractAuditor<AbstractAuditMessageTests.TestAuditMessage> auditor = createTestAuditorWithTemplateInstalled(Version.CURRENT);
auditor.info("foo", "Here is my info");

verify(client).execute(eq(IndexAction.INSTANCE), indexRequestCaptor.capture(), any());
Expand All @@ -121,10 +118,7 @@ public void testInfo() throws IOException {
}

public void testWarning() throws IOException {
AbstractAuditor<AbstractAuditMessageTests.TestAuditMessage> auditor = createTestAuditorWithTemplateInstalled(
client,
Version.CURRENT
);
AbstractAuditor<AbstractAuditMessageTests.TestAuditMessage> auditor = createTestAuditorWithTemplateInstalled(Version.CURRENT);
auditor.warning("bar", "Here is my warning");

verify(client).execute(eq(IndexAction.INSTANCE), indexRequestCaptor.capture(), any());
Expand All @@ -143,10 +137,7 @@ public void testWarning() throws IOException {
}

public void testError() throws IOException {
AbstractAuditor<AbstractAuditMessageTests.TestAuditMessage> auditor = createTestAuditorWithTemplateInstalled(
client,
Version.CURRENT
);
AbstractAuditor<AbstractAuditMessageTests.TestAuditMessage> auditor = createTestAuditorWithTemplateInstalled(Version.CURRENT);
auditor.error("foobar", "Here is my error");

verify(client).execute(eq(IndexAction.INSTANCE), indexRequestCaptor.capture(), any());
Expand All @@ -168,7 +159,7 @@ public void testAuditingBeforeTemplateInstalled() throws Exception {
CountDownLatch writeSomeDocsBeforeTemplateLatch = new CountDownLatch(1);
AbstractAuditor<AbstractAuditMessageTests.TestAuditMessage> auditor =
// TODO: Both this call and the called method can be simplified in versions that will never have to talk to 7.13
createTestAuditorWithoutTemplate(client, randomFrom(Version.CURRENT, Version.V_7_13_0), writeSomeDocsBeforeTemplateLatch);
createTestAuditorWithoutTemplate(randomFrom(Version.CURRENT, Version.V_7_13_0), writeSomeDocsBeforeTemplateLatch);

auditor.error("foobar", "Here is my error to queue");
auditor.warning("foobar", "Here is my warning to queue");
Expand All @@ -192,7 +183,6 @@ public void testAuditingBeforeTemplateInstalled() throws Exception {
public void testMaxBufferSize() throws Exception {
CountDownLatch writeSomeDocsBeforeTemplateLatch = new CountDownLatch(1);
AbstractAuditor<AbstractAuditMessageTests.TestAuditMessage> auditor = createTestAuditorWithoutTemplate(
client,
Version.CURRENT,
writeSomeDocsBeforeTemplateLatch
);
Expand All @@ -219,7 +209,7 @@ private static AbstractAuditMessageTests.TestAuditMessage parseAuditMessage(Byte
return AbstractAuditMessageTests.TestAuditMessage.PARSER.apply(parser, null);
}

private TestAuditor createTestAuditorWithTemplateInstalled(Client client, Version minNodeVersion) {
private TestAuditor createTestAuditorWithTemplateInstalled(Version minNodeVersion) {
ImmutableOpenMap.Builder<String, IndexTemplateMetadata> templates = ImmutableOpenMap.builder(1);
templates.put(TEST_INDEX, mock(IndexTemplateMetadata.class));
Map<String, ComposableIndexTemplate> templatesV2 = Collections.singletonMap(TEST_INDEX, mock(ComposableIndexTemplate.class));
Expand All @@ -238,7 +228,7 @@ private TestAuditor createTestAuditorWithTemplateInstalled(Client client, Versio
}

@SuppressWarnings("unchecked")
private TestAuditor createTestAuditorWithoutTemplate(Client client, Version minNodeVersion, CountDownLatch latch) {
private TestAuditor createTestAuditorWithoutTemplate(Version minNodeVersion, CountDownLatch latch) {
if (Mockito.mockingDetails(client).isMock() == false) {
throw new AssertionError("client should be a mock");
}
Expand Down

0 comments on commit 81ebcbc

Please sign in to comment.