Skip to content

Commit 3743dc6

Browse files
authored
Fix shadowed vars pt4 (#80842) (#80854)
Part of #19752. Fix more instances where local variable names were shadowing field names.
1 parent 607d2e0 commit 3743dc6

File tree

28 files changed

+147
-143
lines changed

28 files changed

+147
-143
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ public void testCreateNullValue() throws Exception {
8484
}
8585

8686
public void testInvalidMustacheTemplate() throws Exception {
87-
AppendProcessor.Factory factory = new AppendProcessor.Factory(TestTemplateService.instance(true));
87+
factory = new AppendProcessor.Factory(TestTemplateService.instance(true));
8888
Map<String, Object> config = new HashMap<>();
8989
config.put("field", "{{field1}}");
9090
config.put("value", "value1");

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ public void testCreateMissingMessageField() throws Exception {
4949
}
5050

5151
public void testInvalidMustacheTemplate() throws Exception {
52-
FailProcessor.Factory factory = new FailProcessor.Factory(TestTemplateService.instance(true));
52+
factory = new FailProcessor.Factory(TestTemplateService.instance(true));
5353
Map<String, Object> config = new HashMap<>();
5454
config.put("message", "{{error}}");
5555
String processorTag = randomAlphaOfLength(10);

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ public void testCreateMissingField() throws Exception {
6666
}
6767

6868
public void testInvalidMustacheTemplate() throws Exception {
69-
RemoveProcessor.Factory factory = new RemoveProcessor.Factory(TestTemplateService.instance(true));
69+
factory = new RemoveProcessor.Factory(TestTemplateService.instance(true));
7070
Map<String, Object> config = new HashMap<>();
7171
config.put("field", "{{field1}}");
7272
String processorTag = randomAlphaOfLength(10);

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ public void testCreateNullValue() throws Exception {
9393
}
9494

9595
public void testInvalidMustacheTemplate() throws Exception {
96-
SetProcessor.Factory factory = new SetProcessor.Factory(TestTemplateService.instance(true));
96+
factory = new SetProcessor.Factory(TestTemplateService.instance(true));
9797
Map<String, Object> config = new HashMap<>();
9898
config.put("field", "{{field1}}");
9999
config.put("value", "value1");

modules/ingest-geoip/src/test/java/org/elasticsearch/ingest/geoip/GeoIpProcessorFactoryTests.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -264,6 +264,7 @@ public void testBuildIllegalFieldOption() throws Exception {
264264
assertThat(e.getMessage(), equalTo("[properties] property isn't a list, but of type [java.lang.String]"));
265265
}
266266

267+
@SuppressWarnings("HiddenField")
267268
public void testLazyLoading() throws Exception {
268269
final Path geoIpDir = createTempDir();
269270
final Path configDir = createTempDir();
@@ -320,6 +321,7 @@ public void testLazyLoading() throws Exception {
320321
assertNotNull(databaseNodeService.getDatabase("GeoLite2-ASN.mmdb", true).databaseReader.get());
321322
}
322323

324+
@SuppressWarnings("HiddenField")
323325
public void testLoadingCustomDatabase() throws IOException {
324326
final Path geoIpDir = createTempDir();
325327
final Path configDir = createTempDir();

modules/lang-expression/src/test/java/org/elasticsearch/script/expression/ExpressionFieldScriptTests.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ public void setUp() throws Exception {
4949
when(fieldData.load(any())).thenReturn(atomicFieldData);
5050

5151
service = new ExpressionScriptEngine();
52-
lookup = new SearchLookup(field -> field.equals("field") ? fieldType : null, (ignored, lookup) -> fieldData);
52+
lookup = new SearchLookup(field -> field.equals("field") ? fieldType : null, (ignored, _lookup) -> fieldData);
5353
}
5454

5555
private FieldScript.LeafFactory compile(String expression) {

modules/lang-expression/src/test/java/org/elasticsearch/script/expression/ExpressionNumberSortScriptTests.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ public void setUp() throws Exception {
5050
when(fieldData.load(any())).thenReturn(atomicFieldData);
5151

5252
service = new ExpressionScriptEngine();
53-
lookup = new SearchLookup(field -> field.equals("field") ? fieldType : null, (ignored, lookup) -> fieldData);
53+
lookup = new SearchLookup(field -> field.equals("field") ? fieldType : null, (ignored, _lookup) -> fieldData);
5454
}
5555

5656
private NumberSortScript.LeafFactory compile(String expression) {

modules/lang-expression/src/test/java/org/elasticsearch/script/expression/ExpressionTermsSetQueryTests.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ public void setUp() throws Exception {
4949
when(fieldData.load(any())).thenReturn(atomicFieldData);
5050

5151
service = new ExpressionScriptEngine();
52-
lookup = new SearchLookup(field -> field.equals("field") ? fieldType : null, (ignored, lookup) -> fieldData);
52+
lookup = new SearchLookup(field -> field.equals("field") ? fieldType : null, (ignored, _lookup) -> fieldData);
5353
}
5454

5555
private TermsSetQueryScript.LeafFactory compile(String expression) {

modules/legacy-geo/src/main/java/org/elasticsearch/legacygeo/builders/CircleBuilder.java

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -102,23 +102,23 @@ public CircleBuilder radius(Distance radius) {
102102

103103
/**
104104
* Set the radius of the circle
105-
* @param radius value of the circles radius
106-
* @param unit unit name of the radius value (see {@link DistanceUnit})
105+
* @param radiusValue value of the circles radius
106+
* @param unitValue unit name of the radius value (see {@link DistanceUnit})
107107
* @return this
108108
*/
109-
public CircleBuilder radius(double radius, String unit) {
110-
return radius(radius, DistanceUnit.fromString(unit));
109+
public CircleBuilder radius(double radiusValue, String unitValue) {
110+
return radius(radiusValue, DistanceUnit.fromString(unitValue));
111111
}
112112

113113
/**
114114
* Set the radius of the circle
115-
* @param radius value of the circles radius
116-
* @param unit unit of the radius value (see {@link DistanceUnit})
115+
* @param radiusValue value of the circles radius
116+
* @param unitValue unit of the radius value (see {@link DistanceUnit})
117117
* @return this
118118
*/
119-
public CircleBuilder radius(double radius, DistanceUnit unit) {
120-
this.unit = unit;
121-
this.radius = radius;
119+
public CircleBuilder radius(double radiusValue, DistanceUnit unitValue) {
120+
this.unit = unitValue;
121+
this.radius = radiusValue;
122122
return this;
123123
}
124124

modules/legacy-geo/src/main/java/org/elasticsearch/legacygeo/builders/GeometryCollectionBuilder.java

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,8 @@ public GeometryCollectionBuilder() {}
4343
* Read from a stream.
4444
*/
4545
public GeometryCollectionBuilder(StreamInput in) throws IOException {
46-
int shapes = in.readVInt();
47-
for (int i = 0; i < shapes; i++) {
46+
int shapesValue = in.readVInt();
47+
for (int i = 0; i < shapesValue; i++) {
4848
shape(in.readNamedWriteable(ShapeBuilder.class));
4949
}
5050
}
@@ -159,15 +159,14 @@ public int numDimensions() {
159159

160160
@Override
161161
public Shape buildS4J() {
162-
163-
List<Shape> shapes = new ArrayList<>(this.shapes.size());
162+
List<Shape> shapesList = new ArrayList<>(this.shapes.size());
164163

165164
for (ShapeBuilder<?, ?, ?> shape : this.shapes) {
166-
shapes.add(shape.buildS4J());
165+
shapesList.add(shape.buildS4J());
167166
}
168167

169-
if (shapes.size() == 1) return shapes.get(0);
170-
else return new XShapeCollection<>(shapes, SPATIAL_CONTEXT);
168+
if (shapesList.size() == 1) return shapesList.get(0);
169+
else return new XShapeCollection<>(shapesList, SPATIAL_CONTEXT);
171170
// note: ShapeCollection is probably faster than a Multi* geom.
172171
}
173172

@@ -176,13 +175,13 @@ public GeometryCollection<Geometry> buildGeometry() {
176175
if (this.shapes.isEmpty()) {
177176
return GeometryCollection.EMPTY;
178177
}
179-
List<Geometry> shapes = new ArrayList<>(this.shapes.size());
178+
List<Geometry> shapesList = new ArrayList<>(this.shapes.size());
180179

181180
for (ShapeBuilder<?, ?, ?> shape : this.shapes) {
182-
shapes.add(shape.buildGeometry());
181+
shapesList.add(shape.buildGeometry());
183182
}
184183

185-
return new GeometryCollection<>(shapes);
184+
return new GeometryCollection<>(shapesList);
186185
}
187186

188187
@Override

modules/legacy-geo/src/main/java/org/elasticsearch/legacygeo/builders/PolygonBuilder.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141
* Methods to wrap polygons at the dateline and building shapes from the data held by the
4242
* builder.
4343
*/
44+
@SuppressWarnings("HiddenField")
4445
public class PolygonBuilder extends ShapeBuilder<JtsGeometry, org.elasticsearch.geometry.Geometry, PolygonBuilder> {
4546

4647
public static final GeoShapeType TYPE = GeoShapeType.POLYGON;
@@ -82,8 +83,8 @@ public PolygonBuilder(CoordinatesBuilder coordinates) {
8283
public PolygonBuilder(StreamInput in) throws IOException {
8384
shell = new LineStringBuilder(in);
8485
orientation = Orientation.readFrom(in);
85-
int holes = in.readVInt();
86-
for (int i = 0; i < holes; i++) {
86+
int holesValue = in.readVInt();
87+
for (int i = 0; i < holesValue; i++) {
8788
hole(new LineStringBuilder(in));
8889
}
8990
}

modules/legacy-geo/src/main/java/org/elasticsearch/legacygeo/builders/ShapeBuilder.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -153,21 +153,21 @@ public E coordinate(Coordinate coordinate) {
153153
/**
154154
* Add a array of coordinates to the collection
155155
*
156-
* @param coordinates array of {@link Coordinate}s to add
156+
* @param coordinatesToAdd array of {@link Coordinate}s to add
157157
* @return this
158158
*/
159-
public E coordinates(Coordinate... coordinates) {
160-
return this.coordinates(Arrays.asList(coordinates));
159+
public E coordinates(Coordinate... coordinatesToAdd) {
160+
return this.coordinates(Arrays.asList(coordinatesToAdd));
161161
}
162162

163163
/**
164164
* Add a collection of coordinates to the collection
165165
*
166-
* @param coordinates array of {@link Coordinate}s to add
166+
* @param coordinatesToAdd array of {@link Coordinate}s to add
167167
* @return this
168168
*/
169-
public E coordinates(Collection<? extends Coordinate> coordinates) {
170-
this.coordinates.addAll(coordinates);
169+
public E coordinates(Collection<? extends Coordinate> coordinatesToAdd) {
170+
this.coordinates.addAll(coordinatesToAdd);
171171
return thisRef();
172172
}
173173

modules/legacy-geo/src/main/java/org/elasticsearch/legacygeo/mapper/LegacyGeoShapeFieldMapper.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -440,11 +440,11 @@ public Query geoShapeQuery(Geometry shape, String fieldName, ShapeRelation relat
440440
public Query geoShapeQuery(
441441
Geometry shape,
442442
String fieldName,
443-
SpatialStrategy strategy,
443+
SpatialStrategy spatialStrategy,
444444
ShapeRelation relation,
445445
SearchExecutionContext context
446446
) {
447-
return queryProcessor.geoShapeQuery(shape, fieldName, strategy, relation, context);
447+
return queryProcessor.geoShapeQuery(shape, fieldName, spatialStrategy, relation, context);
448448
}
449449

450450
@Override
@@ -511,8 +511,8 @@ public PrefixTreeStrategy defaultPrefixTreeStrategy() {
511511
return this.defaultPrefixTreeStrategy;
512512
}
513513

514-
public PrefixTreeStrategy resolvePrefixTreeStrategy(SpatialStrategy strategy) {
515-
return resolvePrefixTreeStrategy(strategy.getStrategyName());
514+
public PrefixTreeStrategy resolvePrefixTreeStrategy(SpatialStrategy spatialStrategy) {
515+
return resolvePrefixTreeStrategy(spatialStrategy.getStrategyName());
516516
}
517517

518518
public PrefixTreeStrategy resolvePrefixTreeStrategy(String strategyName) {

modules/parent-join/src/main/java/org/elasticsearch/join/query/HasChildQueryBuilder.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -132,21 +132,21 @@ protected void doWriteTo(StreamOutput out) throws IOException {
132132
* Defines the minimum number of children that are required to match for the parent to be considered a match and
133133
* the maximum number of children that are required to match for the parent to be considered a match.
134134
*/
135-
public HasChildQueryBuilder minMaxChildren(int minChildren, int maxChildren) {
136-
if (minChildren < 0) {
135+
public HasChildQueryBuilder minMaxChildren(int min, int max) {
136+
if (min < 0) {
137137
throw new IllegalArgumentException("[" + NAME + "] requires non-negative 'min_children' field");
138138
}
139-
if (minChildren == 0) {
139+
if (min == 0) {
140140
deprecationLogger.critical(DeprecationCategory.QUERIES, "min_children", MIN_CHILDREN_0_DEPRECATION_MESSAGE);
141141
}
142-
if (maxChildren < 0) {
142+
if (max < 0) {
143143
throw new IllegalArgumentException("[" + NAME + "] requires non-negative 'max_children' field");
144144
}
145-
if (maxChildren < minChildren) {
145+
if (max < min) {
146146
throw new IllegalArgumentException("[" + NAME + "] 'max_children' is less than 'min_children'");
147147
}
148-
this.minChildren = minChildren;
149-
this.maxChildren = maxChildren;
148+
this.minChildren = min;
149+
this.maxChildren = max;
150150
return this;
151151
}
152152

modules/percolator/src/main/java/org/elasticsearch/percolator/PercolateQueryBuilder.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -514,7 +514,7 @@ protected QueryBuilder doRewrite(QueryRewriteContext queryRewriteContext) {
514514
if (indexedDocumentVersion != null) {
515515
getRequest.version(indexedDocumentVersion);
516516
}
517-
SetOnce<BytesReference> documentSupplier = new SetOnce<>();
517+
SetOnce<BytesReference> docSupplier = new SetOnce<>();
518518
queryRewriteContext.registerAsyncAction((client, listener) -> {
519519
client.get(getRequest, ActionListener.wrap(getResponse -> {
520520
if (getResponse.isExists() == false) {
@@ -535,12 +535,12 @@ protected QueryBuilder doRewrite(QueryRewriteContext queryRewriteContext) {
535535
+ "] source disabled"
536536
);
537537
}
538-
documentSupplier.set(getResponse.getSourceAsBytesRef());
538+
docSupplier.set(getResponse.getSourceAsBytesRef());
539539
listener.onResponse(null);
540540
}, listener::onFailure));
541541
});
542542

543-
PercolateQueryBuilder rewritten = new PercolateQueryBuilder(field, documentType, documentSupplier::get);
543+
PercolateQueryBuilder rewritten = new PercolateQueryBuilder(field, documentType, docSupplier::get);
544544
if (name != null) {
545545
rewritten.setName(name);
546546
}
@@ -615,13 +615,13 @@ protected Analyzer getWrappedAnalyzer(String fieldName) {
615615
}
616616

617617
PercolatorFieldMapper.PercolatorFieldType pft = (PercolatorFieldMapper.PercolatorFieldType) fieldType;
618-
String name = this.name != null ? this.name : pft.name();
618+
String queryName = this.name != null ? this.name : pft.name();
619619
SearchExecutionContext percolateShardContext = wrap(context);
620620
PercolatorFieldMapper.configureContext(percolateShardContext, pft.mapUnmappedFieldsAsText);
621621
;
622622
PercolateQuery.QueryStore queryStore = createStore(pft.queryBuilderField, percolateShardContext);
623623

624-
return pft.percolateQuery(name, queryStore, documents, docSearcher, excludeNestedDocuments, context.indexVersionCreated());
624+
return pft.percolateQuery(queryName, queryStore, documents, docSearcher, excludeNestedDocuments, context.indexVersionCreated());
625625
}
626626

627627
public String getField() {

modules/percolator/src/main/java/org/elasticsearch/percolator/PercolatorFieldMapper.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -373,29 +373,29 @@ Tuple<List<BytesRef>, Map<String, List<byte[]>>> extractTermsAndRanges(IndexRead
373373

374374
@Override
375375
public void parse(DocumentParserContext context) throws IOException {
376-
SearchExecutionContext searchExecutionContext = this.searchExecutionContext.get();
376+
SearchExecutionContext executionContext = this.searchExecutionContext.get();
377377
if (context.doc().getField(queryBuilderField.name()) != null) {
378378
// If a percolator query has been defined in an array object then multiple percolator queries
379379
// could be provided. In order to prevent this we fail if we try to parse more than one query
380380
// for the current document.
381381
throw new IllegalArgumentException("a document can only contain one percolator query");
382382
}
383383

384-
configureContext(searchExecutionContext, isMapUnmappedFieldAsText());
384+
configureContext(executionContext, isMapUnmappedFieldAsText());
385385

386386
XContentParser parser = context.parser();
387387
QueryBuilder queryBuilder = parseQueryBuilder(parser, parser.getTokenLocation());
388388
verifyQuery(queryBuilder);
389389
// Fetching of terms, shapes and indexed scripts happen during this rewrite:
390390
PlainActionFuture<QueryBuilder> future = new PlainActionFuture<>();
391-
Rewriteable.rewriteAndFetch(queryBuilder, searchExecutionContext, future);
391+
Rewriteable.rewriteAndFetch(queryBuilder, executionContext, future);
392392
queryBuilder = future.actionGet();
393393

394394
Version indexVersion = context.indexSettings().getIndexVersionCreated();
395395
createQueryBuilderField(indexVersion, queryBuilderField, queryBuilder, context);
396396

397-
QueryBuilder queryBuilderForProcessing = queryBuilder.rewrite(new SearchExecutionContext(searchExecutionContext));
398-
Query query = queryBuilderForProcessing.toQuery(searchExecutionContext);
397+
QueryBuilder queryBuilderForProcessing = queryBuilder.rewrite(new SearchExecutionContext(executionContext));
398+
Query query = queryBuilderForProcessing.toQuery(executionContext);
399399
processQuery(query, context);
400400
}
401401

modules/percolator/src/main/java/org/elasticsearch/percolator/QueryAnalyzer.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -171,17 +171,17 @@ public QueryVisitor getSubVisitor(Occur occur, Query parent) {
171171
this.verified = false;
172172
return QueryVisitor.EMPTY_VISITOR;
173173
}
174-
int minimumShouldMatch = 0;
174+
int minimumShouldMatchValue = 0;
175175
if (parent instanceof BooleanQuery) {
176176
BooleanQuery bq = (BooleanQuery) parent;
177177
if (bq.getMinimumNumberShouldMatch() == 0
178178
&& bq.clauses().stream().anyMatch(c -> c.getOccur() == Occur.MUST || c.getOccur() == Occur.FILTER)) {
179179
return QueryVisitor.EMPTY_VISITOR;
180180
}
181-
minimumShouldMatch = bq.getMinimumNumberShouldMatch();
181+
minimumShouldMatchValue = bq.getMinimumNumberShouldMatch();
182182
}
183183
ResultBuilder child = new ResultBuilder(version, false);
184-
child.minimumShouldMatch = minimumShouldMatch;
184+
child.minimumShouldMatch = minimumShouldMatchValue;
185185
children.add(child);
186186
return child;
187187
}
@@ -200,9 +200,9 @@ public void visitLeaf(Query query) {
200200
}
201201

202202
@Override
203-
public void consumeTerms(Query query, Term... terms) {
204-
boolean verified = isVerified(query);
205-
Set<QueryExtraction> qe = Arrays.stream(terms).map(QueryExtraction::new).collect(Collectors.toSet());
203+
public void consumeTerms(Query query, Term... termsToConsume) {
204+
boolean isVerified = isVerified(query);
205+
Set<QueryExtraction> qe = Arrays.stream(termsToConsume).map(QueryExtraction::new).collect(Collectors.toSet());
206206
if (qe.size() > 0) {
207207
if (version.before(Version.V_6_1_0) && conjunction) {
208208
Optional<QueryExtraction> longest = qe.stream()
@@ -212,7 +212,7 @@ public void consumeTerms(Query query, Term... terms) {
212212
qe = Collections.singleton(longest.get());
213213
}
214214
}
215-
this.terms.add(new Result(verified, qe, conjunction ? qe.size() : 1));
215+
this.terms.add(new Result(isVerified, qe, conjunction ? qe.size() : 1));
216216
}
217217
}
218218

0 commit comments

Comments
 (0)