Skip to content

Commit 18c3eb7

Browse files
committed
Fix shadowed vars pt6 (#80899)
Part of #19752. Fix more instances where local variable names were shadowing field names.
1 parent ce39b48 commit 18c3eb7

File tree

59 files changed

+403
-398
lines changed

Some content is hidden

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

59 files changed

+403
-398
lines changed

distribution/tools/plugin-cli/src/main/java/org/elasticsearch/plugins/cli/InstallPluginAction.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -467,8 +467,8 @@ Path downloadZip(String urlString, Path tmpDir) throws IOException {
467467
}
468468

469469
// for testing only
470-
void setEnvironment(Environment env) {
471-
this.env = env;
470+
void setEnvironment(Environment environment) {
471+
this.env = environment;
472472
}
473473

474474
// for testing only

distribution/tools/plugin-cli/src/main/java/org/elasticsearch/plugins/cli/SyncPluginsAction.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ public void execute() throws Exception {
113113

114114
// @VisibleForTesting
115115
PluginChanges getPluginChanges(PluginsConfig pluginsConfig, Optional<PluginsConfig> cachedPluginsConfig) throws PluginSyncException {
116-
final List<PluginInfo> existingPlugins = getExistingPlugins(this.env);
116+
final List<PluginInfo> existingPlugins = getExistingPlugins();
117117

118118
final List<PluginDescriptor> pluginsThatShouldExist = pluginsConfig.getPlugins();
119119
final List<PluginDescriptor> pluginsThatActuallyExist = existingPlugins.stream()
@@ -228,7 +228,7 @@ private List<PluginDescriptor> getPluginsToUpgrade(
228228
}).collect(Collectors.toList());
229229
}
230230

231-
private List<PluginInfo> getExistingPlugins(Environment env) throws PluginSyncException {
231+
private List<PluginInfo> getExistingPlugins() throws PluginSyncException {
232232
final List<PluginInfo> plugins = new ArrayList<>();
233233

234234
try {

distribution/tools/plugin-cli/src/test/java/org/elasticsearch/plugins/cli/InstallPluginActionTests.java

Lines changed: 25 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -291,15 +291,15 @@ void installPlugin(PluginDescriptor plugin, Path home, InstallPluginAction actio
291291
}
292292

293293
void installPlugins(final List<PluginDescriptor> plugins, final Path home, final InstallPluginAction action) throws Exception {
294-
final Environment env = TestEnvironment.newEnvironment(Settings.builder().put("path.home", home).build());
295-
action.setEnvironment(env);
294+
final Environment environment = TestEnvironment.newEnvironment(Settings.builder().put("path.home", home).build());
295+
action.setEnvironment(environment);
296296
action.execute(plugins);
297297
}
298298

299-
void assertPlugin(String name, Path original, Environment env) throws IOException {
300-
assertPluginInternal(name, env.pluginsFile(), original);
301-
assertConfigAndBin(name, original, env);
302-
assertInstallCleaned(env);
299+
void assertPlugin(String name, Path original, Environment environment) throws IOException {
300+
assertPluginInternal(name, environment.pluginsFile(), original);
301+
assertConfigAndBin(name, original, environment);
302+
assertInstallCleaned(environment);
303303
}
304304

305305
void assertPluginInternal(String name, Path pluginsFile, Path originalPlugin) throws IOException {
@@ -331,9 +331,9 @@ void assertPluginInternal(String name, Path pluginsFile, Path originalPlugin) th
331331
assertFalse("config was not copied", Files.exists(got.resolve("config")));
332332
}
333333

334-
void assertConfigAndBin(String name, Path original, Environment env) throws IOException {
334+
void assertConfigAndBin(String name, Path original, Environment environment) throws IOException {
335335
if (Files.exists(original.resolve("bin"))) {
336-
Path binDir = env.binFile().resolve(name);
336+
Path binDir = environment.binFile().resolve(name);
337337
assertTrue("bin dir exists", Files.exists(binDir));
338338
assertTrue("bin is a dir", Files.isDirectory(binDir));
339339
try (DirectoryStream<Path> stream = Files.newDirectoryStream(binDir)) {
@@ -347,15 +347,15 @@ void assertConfigAndBin(String name, Path original, Environment env) throws IOEx
347347
}
348348
}
349349
if (Files.exists(original.resolve("config"))) {
350-
Path configDir = env.configFile().resolve(name);
350+
Path configDir = environment.configFile().resolve(name);
351351
assertTrue("config dir exists", Files.exists(configDir));
352352
assertTrue("config is a dir", Files.isDirectory(configDir));
353353

354354
UserPrincipal user = null;
355355
GroupPrincipal group = null;
356356

357357
if (isPosix) {
358-
PosixFileAttributes configAttributes = Files.getFileAttributeView(env.configFile(), PosixFileAttributeView.class)
358+
PosixFileAttributes configAttributes = Files.getFileAttributeView(environment.configFile(), PosixFileAttributeView.class)
359359
.readAttributes();
360360
user = configAttributes.owner();
361361
group = configAttributes.group();
@@ -383,8 +383,8 @@ void assertConfigAndBin(String name, Path original, Environment env) throws IOEx
383383
}
384384
}
385385

386-
void assertInstallCleaned(Environment env) throws IOException {
387-
try (DirectoryStream<Path> stream = Files.newDirectoryStream(env.pluginsFile())) {
386+
void assertInstallCleaned(Environment environment) throws IOException {
387+
try (DirectoryStream<Path> stream = Files.newDirectoryStream(environment.pluginsFile())) {
388388
for (Path file : stream) {
389389
if (file.getFileName().toString().startsWith(".installing")) {
390390
fail("Installation dir still exists, " + file);
@@ -598,22 +598,22 @@ public void testBinPermissions() throws Exception {
598598
public void testPluginPermissions() throws Exception {
599599
assumeTrue("posix filesystem", isPosix);
600600

601-
final Path pluginDir = createPluginDir(temp);
602-
final Path resourcesDir = pluginDir.resolve("resources");
603-
final Path platformDir = pluginDir.resolve("platform");
601+
final Path tempPluginDir = createPluginDir(temp);
602+
final Path resourcesDir = tempPluginDir.resolve("resources");
603+
final Path platformDir = tempPluginDir.resolve("platform");
604604
final Path platformNameDir = platformDir.resolve("linux-x86_64");
605605
final Path platformBinDir = platformNameDir.resolve("bin");
606606
Files.createDirectories(platformBinDir);
607607

608-
Files.createFile(pluginDir.resolve("fake-" + Version.CURRENT.toString() + ".jar"));
608+
Files.createFile(tempPluginDir.resolve("fake-" + Version.CURRENT.toString() + ".jar"));
609609
Files.createFile(platformBinDir.resolve("fake_executable"));
610610
Files.createDirectory(resourcesDir);
611611
Files.createFile(resourcesDir.resolve("resource"));
612612

613-
final PluginDescriptor pluginZip = createPluginZip("fake", pluginDir);
613+
final PluginDescriptor pluginZip = createPluginZip("fake", tempPluginDir);
614614

615615
installPlugin(pluginZip);
616-
assertPlugin("fake", pluginDir, env.v2());
616+
assertPlugin("fake", tempPluginDir, env.v2());
617617

618618
final Path fake = env.v2().pluginsFile().resolve("fake");
619619
final Path resources = fake.resolve("resources");
@@ -729,9 +729,9 @@ public void testZipRelativeOutsideEntryName() throws Exception {
729729
}
730730

731731
public void testOfficialPluginsHelpSortedAndMissingObviouslyWrongPlugins() throws Exception {
732-
MockTerminal terminal = new MockTerminal();
733-
new MockInstallPluginCommand().main(new String[] { "--help" }, terminal);
734-
try (BufferedReader reader = new BufferedReader(new StringReader(terminal.getOutput()))) {
732+
MockTerminal mockTerminal = new MockTerminal();
733+
new MockInstallPluginCommand().main(new String[] { "--help" }, mockTerminal);
734+
try (BufferedReader reader = new BufferedReader(new StringReader(mockTerminal.getOutput()))) {
735735
String line = reader.readLine();
736736

737737
// first find the beginning of our list of official plugins
@@ -1360,7 +1360,8 @@ private String signature(final byte[] bytes, final PGPSecretKey secretKey) {
13601360

13611361
// checks the plugin requires a policy confirmation, and does not install when that is rejected by the user
13621362
// the plugin is installed after this method completes
1363-
private void assertPolicyConfirmation(Tuple<Path, Environment> env, PluginDescriptor pluginZip, String... warnings) throws Exception {
1363+
private void assertPolicyConfirmation(Tuple<Path, Environment> pathEnvironmentTuple, PluginDescriptor pluginZip, String... warnings)
1364+
throws Exception {
13641365
for (int i = 0; i < warnings.length; ++i) {
13651366
String warning = warnings[i];
13661367
for (int j = 0; j < i; ++j) {
@@ -1372,7 +1373,7 @@ private void assertPolicyConfirmation(Tuple<Path, Environment> env, PluginDescri
13721373
assertThat(e.getMessage(), containsString("installation aborted by user"));
13731374

13741375
assertThat(terminal.getErrorOutput(), containsString("WARNING: " + warning));
1375-
try (Stream<Path> fileStream = Files.list(env.v2().pluginsFile())) {
1376+
try (Stream<Path> fileStream = Files.list(pathEnvironmentTuple.v2().pluginsFile())) {
13761377
assertThat(fileStream.collect(Collectors.toList()), empty());
13771378
}
13781379

@@ -1385,7 +1386,7 @@ private void assertPolicyConfirmation(Tuple<Path, Environment> env, PluginDescri
13851386
e = expectThrows(UserException.class, () -> installPlugin(pluginZip));
13861387
assertThat(e.getMessage(), containsString("installation aborted by user"));
13871388
assertThat(terminal.getErrorOutput(), containsString("WARNING: " + warning));
1388-
try (Stream<Path> fileStream = Files.list(env.v2().pluginsFile())) {
1389+
try (Stream<Path> fileStream = Files.list(pathEnvironmentTuple.v2().pluginsFile())) {
13891390
assertThat(fileStream.collect(Collectors.toList()), empty());
13901391
}
13911392
}

qa/full-cluster-restart/src/test/java/org/elasticsearch/upgrades/FullClusterRestartIT.java

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -782,7 +782,7 @@ public void testSingleDoc() throws IOException {
782782
* Tests that a single empty shard index is correctly recovered. Empty shards are often an edge case.
783783
*/
784784
public void testEmptyShard() throws IOException {
785-
final String index = "test_empty_shard";
785+
final String indexName = "test_empty_shard";
786786

787787
if (isRunningAgainstOldCluster()) {
788788
Settings.Builder settings = Settings.builder()
@@ -794,9 +794,9 @@ public void testEmptyShard() throws IOException {
794794
// before timing out
795795
.put(INDEX_DELAYED_NODE_LEFT_TIMEOUT_SETTING.getKey(), "100ms")
796796
.put(SETTING_ALLOCATION_MAX_RETRY.getKey(), "0"); // fail faster
797-
createIndex(index, settings.build());
797+
createIndex(indexName, settings.build());
798798
}
799-
ensureGreen(index);
799+
ensureGreen(indexName);
800800
}
801801

802802
/**
@@ -1165,21 +1165,24 @@ public void testClosedIndices() throws Exception {
11651165
* that the index has started shards.
11661166
*/
11671167
@SuppressWarnings("unchecked")
1168-
private void assertClosedIndex(final String index, final boolean checkRoutingTable) throws IOException {
1168+
private void assertClosedIndex(final String indexName, final boolean checkRoutingTable) throws IOException {
11691169
final Map<String, ?> state = entityAsMap(client().performRequest(new Request("GET", "/_cluster/state")));
11701170

1171-
final Map<String, ?> metadata = (Map<String, Object>) XContentMapValues.extractValue("metadata.indices." + index, state);
1171+
final Map<String, ?> metadata = (Map<String, Object>) XContentMapValues.extractValue("metadata.indices." + indexName, state);
11721172
assertThat(metadata, notNullValue());
11731173
assertThat(metadata.get("state"), equalTo("close"));
11741174

1175-
final Map<String, ?> blocks = (Map<String, Object>) XContentMapValues.extractValue("blocks.indices." + index, state);
1175+
final Map<String, ?> blocks = (Map<String, Object>) XContentMapValues.extractValue("blocks.indices." + indexName, state);
11761176
assertThat(blocks, notNullValue());
11771177
assertThat(blocks.containsKey(String.valueOf(MetadataIndexStateService.INDEX_CLOSED_BLOCK_ID)), is(true));
11781178

11791179
final Map<String, ?> settings = (Map<String, Object>) XContentMapValues.extractValue("settings", metadata);
11801180
assertThat(settings, notNullValue());
11811181

1182-
final Map<String, ?> routingTable = (Map<String, Object>) XContentMapValues.extractValue("routing_table.indices." + index, state);
1182+
final Map<String, ?> routingTable = (Map<String, Object>) XContentMapValues.extractValue(
1183+
"routing_table.indices." + indexName,
1184+
state
1185+
);
11831186
if (checkRoutingTable) {
11841187
assertThat(routingTable, notNullValue());
11851188
assertThat(Booleans.parseBoolean((String) XContentMapValues.extractValue("index.verified_before_close", settings)), is(true));
@@ -1198,7 +1201,7 @@ private void assertClosedIndex(final String index, final boolean checkRoutingTab
11981201
for (Map<String, ?> shard : shards) {
11991202
assertThat(XContentMapValues.extractValue("shard", shard), equalTo(i));
12001203
assertThat(XContentMapValues.extractValue("state", shard), equalTo("STARTED"));
1201-
assertThat(XContentMapValues.extractValue("index", shard), equalTo(index));
1204+
assertThat(XContentMapValues.extractValue("index", shard), equalTo(indexName));
12021205
}
12031206
}
12041207
} else {
@@ -1353,12 +1356,12 @@ private String loadInfoDocument(String id) throws IOException {
13531356
return m.group(1);
13541357
}
13551358

1356-
private List<String> dataNodes(String index, RestClient client) throws IOException {
1357-
Request request = new Request("GET", index + "/_stats");
1359+
private List<String> dataNodes(String indexName, RestClient client) throws IOException {
1360+
Request request = new Request("GET", indexName + "/_stats");
13581361
request.addParameter("level", "shards");
13591362
Response response = client.performRequest(request);
13601363
List<String> nodes = new ArrayList<>();
1361-
List<Object> shardStats = ObjectPath.createFromResponse(response).evaluate("indices." + index + ".shards.0");
1364+
List<Object> shardStats = ObjectPath.createFromResponse(response).evaluate("indices." + indexName + ".shards.0");
13621365
for (Object shard : shardStats) {
13631366
final String nodeId = ObjectPath.evaluate(shard, "routing.node");
13641367
nodes.add(nodeId);
@@ -1370,8 +1373,8 @@ private List<String> dataNodes(String index, RestClient client) throws IOExcepti
13701373
* Wait for an index to have green health, waiting longer than
13711374
* {@link ESRestTestCase#ensureGreen}.
13721375
*/
1373-
protected void ensureGreenLongWait(String index) throws IOException {
1374-
Request request = new Request("GET", "/_cluster/health/" + index);
1376+
protected void ensureGreenLongWait(String indexName) throws IOException {
1377+
Request request = new Request("GET", "/_cluster/health/" + indexName);
13751378
request.addParameter("timeout", "2m");
13761379
request.addParameter("wait_for_status", "green");
13771380
request.addParameter("wait_for_no_relocating_shards", "true");

qa/os/src/test/java/org/elasticsearch/packaging/test/PackagingTestCase.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -126,12 +126,12 @@ public abstract class PackagingTestCase extends Assert {
126126
// the java installation already installed on the system
127127
protected static final String systemJavaHome;
128128
static {
129-
Shell sh = new Shell();
129+
Shell initShell = new Shell();
130130
if (Platforms.WINDOWS) {
131-
systemJavaHome = sh.run("$Env:SYSTEM_JAVA_HOME").stdout.trim();
131+
systemJavaHome = initShell.run("$Env:SYSTEM_JAVA_HOME").stdout.trim();
132132
} else {
133133
assert Platforms.LINUX || Platforms.DARWIN;
134-
systemJavaHome = sh.run("echo $SYSTEM_JAVA_HOME").stdout.trim();
134+
systemJavaHome = initShell.run("echo $SYSTEM_JAVA_HOME").stdout.trim();
135135
}
136136
}
137137

qa/os/src/test/java/org/elasticsearch/packaging/util/Distribution.java

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -43,12 +43,8 @@ public Distribution(Path path) {
4343

4444
this.platform = filename.contains("windows") ? Platform.WINDOWS : Platform.LINUX;
4545
this.hasJdk = filename.contains("no-jdk") == false;
46-
String version = filename.split("-", 3)[1];
47-
this.baseVersion = version;
48-
if (filename.contains("-SNAPSHOT")) {
49-
version += "-SNAPSHOT";
50-
}
51-
this.version = version;
46+
this.baseVersion = filename.split("-", 3)[1];
47+
this.version = filename.contains("-SNAPSHOT") ? this.baseVersion + "-SNAPSHOT" : this.baseVersion;
5248
}
5349

5450
public boolean isArchive() {

qa/os/src/test/java/org/elasticsearch/packaging/util/docker/DockerRun.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -70,18 +70,18 @@ public DockerRun volume(Path from, Path to) {
7070
/**
7171
* Sets the UID that the container is run with, and the GID too if specified.
7272
*
73-
* @param uid the UID to use, or {@code null} to use the image default
74-
* @param gid the GID to use, or {@code null} to use the image default
73+
* @param uidToUse the UID to use, or {@code null} to use the image default
74+
* @param gidToUse the GID to use, or {@code null} to use the image default
7575
* @return the current builder
7676
*/
77-
public DockerRun uid(Integer uid, Integer gid) {
78-
if (uid == null) {
79-
if (gid != null) {
77+
public DockerRun uid(Integer uidToUse, Integer gidToUse) {
78+
if (uidToUse == null) {
79+
if (gidToUse != null) {
8080
throw new IllegalArgumentException("Cannot override GID without also overriding UID");
8181
}
8282
}
83-
this.uid = uid;
84-
this.gid = gid;
83+
this.uid = uidToUse;
84+
this.gid = gidToUse;
8585
return this;
8686
}
8787

server/src/test/java/org/elasticsearch/index/replication/RetentionLeasesReplicationTests.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -75,8 +75,8 @@ public void testOutOfOrderRetentionLeasesRequests() throws Exception {
7575
IndexMetadata indexMetadata = buildIndexMetadata(numberOfReplicas, settings, indexMapping);
7676
try (ReplicationGroup group = new ReplicationGroup(indexMetadata) {
7777
@Override
78-
protected void syncRetentionLeases(ShardId shardId, RetentionLeases leases, ActionListener<ReplicationResponse> listener) {
79-
listener.onResponse(new SyncRetentionLeasesResponse(new RetentionLeaseSyncAction.Request(shardId, leases)));
78+
protected void syncRetentionLeases(ShardId id, RetentionLeases leases, ActionListener<ReplicationResponse> listener) {
79+
listener.onResponse(new SyncRetentionLeasesResponse(new RetentionLeaseSyncAction.Request(id, leases)));
8080
}
8181
}) {
8282
group.startAll();
@@ -102,8 +102,8 @@ public void testSyncRetentionLeasesWithPrimaryPromotion() throws Exception {
102102
IndexMetadata indexMetadata = buildIndexMetadata(numberOfReplicas, settings, indexMapping);
103103
try (ReplicationGroup group = new ReplicationGroup(indexMetadata) {
104104
@Override
105-
protected void syncRetentionLeases(ShardId shardId, RetentionLeases leases, ActionListener<ReplicationResponse> listener) {
106-
listener.onResponse(new SyncRetentionLeasesResponse(new RetentionLeaseSyncAction.Request(shardId, leases)));
105+
protected void syncRetentionLeases(ShardId id, RetentionLeases leases, ActionListener<ReplicationResponse> listener) {
106+
listener.onResponse(new SyncRetentionLeasesResponse(new RetentionLeaseSyncAction.Request(id, leases)));
107107
}
108108
}) {
109109
group.startAll();

test/framework/src/main/java/org/elasticsearch/cluster/DiskUsageIntegTestCase.java

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -114,11 +114,11 @@ public String name() {
114114

115115
@Override
116116
public long getTotalSpace() throws IOException {
117-
final long totalSpace = this.totalSpace;
118-
if (totalSpace == -1) {
117+
final long totalSpaceCopy = this.totalSpace;
118+
if (totalSpaceCopy == -1) {
119119
return super.getTotalSpace();
120120
} else {
121-
return totalSpace;
121+
return totalSpaceCopy;
122122
}
123123
}
124124

@@ -129,21 +129,21 @@ public void setTotalSpace(long totalSpace) {
129129

130130
@Override
131131
public long getUsableSpace() throws IOException {
132-
final long totalSpace = this.totalSpace;
133-
if (totalSpace == -1) {
132+
final long totalSpaceCopy = this.totalSpace;
133+
if (totalSpaceCopy == -1) {
134134
return super.getUsableSpace();
135135
} else {
136-
return Math.max(0L, totalSpace - getTotalFileSize(path));
136+
return Math.max(0L, totalSpaceCopy - getTotalFileSize(path));
137137
}
138138
}
139139

140140
@Override
141141
public long getUnallocatedSpace() throws IOException {
142-
final long totalSpace = this.totalSpace;
143-
if (totalSpace == -1) {
142+
final long totalSpaceCopy = this.totalSpace;
143+
if (totalSpaceCopy == -1) {
144144
return super.getUnallocatedSpace();
145145
} else {
146-
return Math.max(0L, totalSpace - getTotalFileSize(path));
146+
return Math.max(0L, totalSpaceCopy - getTotalFileSize(path));
147147
}
148148
}
149149

0 commit comments

Comments
 (0)