diff --git a/build-conventions/src/main/java/org/elasticsearch/gradle/internal/checkstyle/HiddenFieldCheck.java b/build-conventions/src/main/java/org/elasticsearch/gradle/internal/checkstyle/HiddenFieldCheck.java index e67ee1a30624..23155cc2971e 100644 --- a/build-conventions/src/main/java/org/elasticsearch/gradle/internal/checkstyle/HiddenFieldCheck.java +++ b/build-conventions/src/main/java/org/elasticsearch/gradle/internal/checkstyle/HiddenFieldCheck.java @@ -365,7 +365,8 @@ public class HiddenFieldCheck extends AbstractCheck { // we should not capitalize the first character if the second // one is a capital one, since according to JavaBeans spec // setXYzz() is a setter for XYzz property, not for xYzz one. - if (name.length() == 1 || Character.isUpperCase(name.charAt(1)) == false) { + // @pugnascotia: unless the first char is 'x'. + if (name.length() == 1 || (Character.isUpperCase(name.charAt(1)) == false || name.charAt(0) == 'x')) { setterName = name.substring(0, 1).toUpperCase(Locale.ENGLISH) + name.substring(1); } return setterName; diff --git a/modules/lang-painless/src/doc/java/org/elasticsearch/painless/ContextApiSpecGenerator.java b/modules/lang-painless/src/doc/java/org/elasticsearch/painless/ContextApiSpecGenerator.java index 08430e95f660..60745ed18397 100644 --- a/modules/lang-painless/src/doc/java/org/elasticsearch/painless/ContextApiSpecGenerator.java +++ b/modules/lang-painless/src/doc/java/org/elasticsearch/painless/ContextApiSpecGenerator.java @@ -132,9 +132,9 @@ public class ContextApiSpecGenerator { return new FileInputStream(classPath.toFile()); } else { String packageName = className.substring(0, className.lastIndexOf(".")); - Path root = pkgRoots.get(packageName); - if (root != null) { - Path classPath = root.resolve(className.substring(className.lastIndexOf(".") + 1) + ".java"); + Path packageRoot = pkgRoots.get(packageName); + if (packageRoot != null) { + Path classPath = packageRoot.resolve(className.substring(className.lastIndexOf(".") + 1) + ".java"); return new FileInputStream(classPath.toFile()); } } diff --git a/modules/lang-painless/src/doc/java/org/elasticsearch/painless/ContextGeneratorCommon.java b/modules/lang-painless/src/doc/java/org/elasticsearch/painless/ContextGeneratorCommon.java index 20be705e06af..17c835f5a96a 100644 --- a/modules/lang-painless/src/doc/java/org/elasticsearch/painless/ContextGeneratorCommon.java +++ b/modules/lang-painless/src/doc/java/org/elasticsearch/painless/ContextGeneratorCommon.java @@ -209,16 +209,16 @@ public class ContextGeneratorCommon { } } - private Set getCommon(List contexts, Function> getter) { + private Set getCommon(List painlessContexts, Function> getter) { Map infoCounts = new HashMap<>(); - for (PainlessContextInfo contextInfo : contexts) { + for (PainlessContextInfo contextInfo : painlessContexts) { for (T info : getter.apply(contextInfo)) { infoCounts.merge(info, 1, Integer::sum); } } return infoCounts.entrySet() .stream() - .filter(e -> e.getValue() == contexts.size()) + .filter(e -> e.getValue() == painlessContexts.size()) .map(Map.Entry::getKey) .collect(Collectors.toSet()); } diff --git a/modules/lang-painless/src/main/java/org/elasticsearch/painless/Compiler.java b/modules/lang-painless/src/main/java/org/elasticsearch/painless/Compiler.java index d30874e65f0f..718f8e809257 100644 --- a/modules/lang-painless/src/main/java/org/elasticsearch/painless/Compiler.java +++ b/modules/lang-painless/src/main/java/org/elasticsearch/painless/Compiler.java @@ -167,12 +167,12 @@ final class Compiler { Compiler(Class scriptClass, Class factoryClass, Class statefulFactoryClass, PainlessLookup painlessLookup) { this.scriptClass = scriptClass; this.painlessLookup = painlessLookup; - Map> additionalClasses = new HashMap<>(); - additionalClasses.put(scriptClass.getName(), scriptClass); - addFactoryMethod(additionalClasses, factoryClass, "newInstance"); - addFactoryMethod(additionalClasses, statefulFactoryClass, "newFactory"); - addFactoryMethod(additionalClasses, statefulFactoryClass, "newInstance"); - this.additionalClasses = Collections.unmodifiableMap(additionalClasses); + Map> additionalClassMap = new HashMap<>(); + additionalClassMap.put(scriptClass.getName(), scriptClass); + addFactoryMethod(additionalClassMap, factoryClass, "newInstance"); + addFactoryMethod(additionalClassMap, statefulFactoryClass, "newFactory"); + addFactoryMethod(additionalClassMap, statefulFactoryClass, "newInstance"); + this.additionalClasses = Collections.unmodifiableMap(additionalClassMap); } private static void addFactoryMethod(Map> additionalClasses, Class factoryClass, String methodName) { diff --git a/modules/lang-painless/src/main/java/org/elasticsearch/painless/CompilerSettings.java b/modules/lang-painless/src/main/java/org/elasticsearch/painless/CompilerSettings.java index 946e9e85308d..5dfe2f19604c 100644 --- a/modules/lang-painless/src/main/java/org/elasticsearch/painless/CompilerSettings.java +++ b/modules/lang-painless/src/main/java/org/elasticsearch/painless/CompilerSettings.java @@ -171,14 +171,14 @@ public final class CompilerSettings { * annotation. */ public Map asMap() { - int regexLimitFactor = this.regexLimitFactor; + int regexLimitFactorToApply = this.regexLimitFactor; if (regexesEnabled == RegexEnabled.TRUE) { - regexLimitFactor = Augmentation.UNLIMITED_PATTERN_FACTOR; + regexLimitFactorToApply = Augmentation.UNLIMITED_PATTERN_FACTOR; } else if (regexesEnabled == RegexEnabled.FALSE) { - regexLimitFactor = Augmentation.DISABLED_PATTERN_FACTOR; + regexLimitFactorToApply = Augmentation.DISABLED_PATTERN_FACTOR; } Map map = new HashMap<>(); - map.put("regex_limit_factor", regexLimitFactor); + map.put("regex_limit_factor", regexLimitFactorToApply); // for testing only map.put("testInject0", testInject0); diff --git a/modules/lang-painless/src/main/java/org/elasticsearch/painless/DefBootstrap.java b/modules/lang-painless/src/main/java/org/elasticsearch/painless/DefBootstrap.java index 5fb478c8d5a0..1aea004e92cf 100644 --- a/modules/lang-painless/src/main/java/org/elasticsearch/painless/DefBootstrap.java +++ b/modules/lang-painless/src/main/java/org/elasticsearch/painless/DefBootstrap.java @@ -155,14 +155,14 @@ public final class DefBootstrap { /** * Does a slow lookup against the whitelist. */ - private MethodHandle lookup(int flavor, String name, Class receiver) throws Throwable { - switch (flavor) { + private MethodHandle lookup(int flavorValue, String nameValue, Class receiver) throws Throwable { + switch (flavorValue) { case METHOD_CALL: - return Def.lookupMethod(painlessLookup, functions, constants, methodHandlesLookup, type(), receiver, name, args); + return Def.lookupMethod(painlessLookup, functions, constants, methodHandlesLookup, type(), receiver, nameValue, args); case LOAD: - return Def.lookupGetter(painlessLookup, receiver, name); + return Def.lookupGetter(painlessLookup, receiver, nameValue); case STORE: - return Def.lookupSetter(painlessLookup, receiver, name); + return Def.lookupSetter(painlessLookup, receiver, nameValue); case ARRAY_LOAD: return Def.lookupArrayLoad(receiver); case ARRAY_STORE: @@ -170,7 +170,15 @@ public final class DefBootstrap { case ITERATOR: return Def.lookupIterator(receiver); case REFERENCE: - return Def.lookupReference(painlessLookup, functions, constants, methodHandlesLookup, (String) args[0], receiver, name); + return Def.lookupReference( + painlessLookup, + functions, + constants, + methodHandlesLookup, + (String) args[0], + receiver, + nameValue + ); case INDEX_NORMALIZE: return Def.lookupIndexNormalize(receiver); default: diff --git a/modules/lang-painless/src/main/java/org/elasticsearch/painless/PainlessScriptEngine.java b/modules/lang-painless/src/main/java/org/elasticsearch/painless/PainlessScriptEngine.java index 45056b26f683..27e02a4a7c30 100644 --- a/modules/lang-painless/src/main/java/org/elasticsearch/painless/PainlessScriptEngine.java +++ b/modules/lang-painless/src/main/java/org/elasticsearch/painless/PainlessScriptEngine.java @@ -81,21 +81,21 @@ public final class PainlessScriptEngine implements ScriptEngine { defaultCompilerSettings.setRegexesEnabled(CompilerSettings.REGEX_ENABLED.get(settings)); defaultCompilerSettings.setRegexLimitFactor(CompilerSettings.REGEX_LIMIT_FACTOR.get(settings)); - Map, Compiler> contextsToCompilers = new HashMap<>(); - Map, PainlessLookup> contextsToLookups = new HashMap<>(); + Map, Compiler> mutableContextsToCompilers = new HashMap<>(); + Map, PainlessLookup> mutableContextsToLookups = new HashMap<>(); for (Map.Entry, List> entry : contexts.entrySet()) { ScriptContext context = entry.getKey(); PainlessLookup lookup = PainlessLookupBuilder.buildFromWhitelists(entry.getValue()); - contextsToCompilers.put( + mutableContextsToCompilers.put( context, new Compiler(context.instanceClazz, context.factoryClazz, context.statefulFactoryClazz, lookup) ); - contextsToLookups.put(context, lookup); + mutableContextsToLookups.put(context, lookup); } - this.contextsToCompilers = Collections.unmodifiableMap(contextsToCompilers); - this.contextsToLookups = Collections.unmodifiableMap(contextsToLookups); + this.contextsToCompilers = Collections.unmodifiableMap(mutableContextsToCompilers); + this.contextsToLookups = Collections.unmodifiableMap(mutableContextsToLookups); } public Map, PainlessLookup> getContextsToLookups() { diff --git a/modules/lang-painless/src/main/java/org/elasticsearch/painless/ScriptClassInfo.java b/modules/lang-painless/src/main/java/org/elasticsearch/painless/ScriptClassInfo.java index 869cdb54ca7c..cb666eb5b939 100644 --- a/modules/lang-painless/src/main/java/org/elasticsearch/painless/ScriptClassInfo.java +++ b/modules/lang-painless/src/main/java/org/elasticsearch/painless/ScriptClassInfo.java @@ -39,6 +39,7 @@ public class ScriptClassInfo { public final List converters; public final FunctionTable.LocalFunction defConverter; + @SuppressWarnings("HiddenField") public ScriptClassInfo(PainlessLookup painlessLookup, Class baseClass) { this.baseClass = baseClass; diff --git a/modules/lang-painless/src/main/java/org/elasticsearch/painless/action/PainlessExecuteAction.java b/modules/lang-painless/src/main/java/org/elasticsearch/painless/action/PainlessExecuteAction.java index 95b3c611495c..968634e1604c 100644 --- a/modules/lang-painless/src/main/java/org/elasticsearch/painless/action/PainlessExecuteAction.java +++ b/modules/lang-painless/src/main/java/org/elasticsearch/painless/action/PainlessExecuteAction.java @@ -196,9 +196,9 @@ public class PainlessExecuteAction extends ActionType { return identifier++; } - private SourceContext buildAntlrTree(String source) { - ANTLRInputStream stream = new ANTLRInputStream(source); + private SourceContext buildAntlrTree(String sourceString) { + ANTLRInputStream stream = new ANTLRInputStream(sourceString); PainlessLexer lexer = new EnhancedPainlessLexer(stream, sourceName); PainlessParser parser = new PainlessParser(new CommonTokenStream(lexer)); ParserErrorStrategy strategy = new ParserErrorStrategy(sourceName); diff --git a/modules/lang-painless/src/main/java/org/elasticsearch/painless/ir/ForLoopNode.java b/modules/lang-painless/src/main/java/org/elasticsearch/painless/ir/ForLoopNode.java index bda4c583ba59..e7bf1e3cbe21 100644 --- a/modules/lang-painless/src/main/java/org/elasticsearch/painless/ir/ForLoopNode.java +++ b/modules/lang-painless/src/main/java/org/elasticsearch/painless/ir/ForLoopNode.java @@ -18,7 +18,7 @@ public class ForLoopNode extends ConditionNode { private IRNode initializerNode; private ExpressionNode afterthoughtNode; - public void setInitialzerNode(IRNode initializerNode) { + public void setInitializerNode(IRNode initializerNode) { this.initializerNode = initializerNode; } diff --git a/modules/lang-painless/src/main/java/org/elasticsearch/painless/phase/DefaultConstantFoldingOptimizationPhase.java b/modules/lang-painless/src/main/java/org/elasticsearch/painless/phase/DefaultConstantFoldingOptimizationPhase.java index 6dc1a980be23..33ec5e7e5e0f 100644 --- a/modules/lang-painless/src/main/java/org/elasticsearch/painless/phase/DefaultConstantFoldingOptimizationPhase.java +++ b/modules/lang-painless/src/main/java/org/elasticsearch/painless/phase/DefaultConstantFoldingOptimizationPhase.java @@ -116,7 +116,7 @@ public class DefaultConstantFoldingOptimizationPhase extends IRTreeBaseVisitor scope) { if (irForLoopNode.getInitializerNode() != null) { - irForLoopNode.getInitializerNode().visit(this, irForLoopNode::setInitialzerNode); + irForLoopNode.getInitializerNode().visit(this, irForLoopNode::setInitializerNode); } if (irForLoopNode.getConditionNode() != null) { diff --git a/modules/lang-painless/src/main/java/org/elasticsearch/painless/phase/DefaultUserTreeToIRTreePhase.java b/modules/lang-painless/src/main/java/org/elasticsearch/painless/phase/DefaultUserTreeToIRTreePhase.java index bb2f21baa2e6..0fc229aea93b 100644 --- a/modules/lang-painless/src/main/java/org/elasticsearch/painless/phase/DefaultUserTreeToIRTreePhase.java +++ b/modules/lang-painless/src/main/java/org/elasticsearch/painless/phase/DefaultUserTreeToIRTreePhase.java @@ -714,7 +714,7 @@ public class DefaultUserTreeToIRTreePhase implements UserTreeVisitor exec(script)); assertTrue(cbe.getMessage().contains(regexCircuitMessage)); - assertTrue(cbe.getMessage().contains(charSequence.subSequence(0, 61) + "...")); + assertTrue(cbe.getMessage().contains(longCharSequence.subSequence(0, 61) + "...")); } private void setRegexLimitFactor(int factor) { diff --git a/plugins/analysis-kuromoji/src/main/java/org/elasticsearch/plugin/analysis/kuromoji/KuromojiTokenizerFactory.java b/plugins/analysis-kuromoji/src/main/java/org/elasticsearch/plugin/analysis/kuromoji/KuromojiTokenizerFactory.java index 12efa4abc111..0df04335aaed 100644 --- a/plugins/analysis-kuromoji/src/main/java/org/elasticsearch/plugin/analysis/kuromoji/KuromojiTokenizerFactory.java +++ b/plugins/analysis-kuromoji/src/main/java/org/elasticsearch/plugin/analysis/kuromoji/KuromojiTokenizerFactory.java @@ -105,11 +105,11 @@ public class KuromojiTokenizerFactory extends AbstractTokenizerFactory { @Override public Tokenizer create() { JapaneseTokenizer t = new JapaneseTokenizer(userDictionary, discardPunctuation, discardCompoundToken, mode); - int nBestCost = this.nBestCost; + int nBestCostValue = this.nBestCost; if (nBestExamples != null) { - nBestCost = Math.max(nBestCost, t.calcNBestCost(nBestExamples)); + nBestCostValue = Math.max(nBestCostValue, t.calcNBestCost(nBestExamples)); } - t.setNBestCost(nBestCost); + t.setNBestCost(nBestCostValue); return t; } diff --git a/plugins/discovery-azure-classic/src/internalClusterTest/java/org/elasticsearch/cloud/azure/classic/AbstractAzureComputeServiceTestCase.java b/plugins/discovery-azure-classic/src/internalClusterTest/java/org/elasticsearch/cloud/azure/classic/AbstractAzureComputeServiceTestCase.java index d96b987878f3..39d468786f07 100644 --- a/plugins/discovery-azure-classic/src/internalClusterTest/java/org/elasticsearch/cloud/azure/classic/AbstractAzureComputeServiceTestCase.java +++ b/plugins/discovery-azure-classic/src/internalClusterTest/java/org/elasticsearch/cloud/azure/classic/AbstractAzureComputeServiceTestCase.java @@ -147,22 +147,22 @@ public abstract class AbstractAzureComputeServiceTestCase extends ESIntegTestCas */ @Override protected AzureSeedHostsProvider createSeedHostsProvider( - final Settings settings, + final Settings settingsToUse, final AzureComputeService azureComputeService, final TransportService transportService, final NetworkService networkService ) { - return new AzureSeedHostsProvider(settings, azureComputeService, transportService, networkService) { + return new AzureSeedHostsProvider(settingsToUse, azureComputeService, transportService, networkService) { @Override - protected String resolveInstanceAddress(final HostType hostType, final RoleInstance instance) { - if (hostType == HostType.PRIVATE_IP) { + protected String resolveInstanceAddress(final HostType hostTypeValue, final RoleInstance instance) { + if (hostTypeValue == HostType.PRIVATE_IP) { DiscoveryNode discoveryNode = nodes.get(instance.getInstanceName()); if (discoveryNode != null) { // Format the InetSocketAddress to a format that contains the port number return NetworkAddress.format(discoveryNode.getAddress().address()); } } - return super.resolveInstanceAddress(hostType, instance); + return super.resolveInstanceAddress(hostTypeValue, instance); } }; } diff --git a/plugins/discovery-azure-classic/src/main/java/org/elasticsearch/discovery/azure/classic/AzureSeedHostsProvider.java b/plugins/discovery-azure-classic/src/main/java/org/elasticsearch/discovery/azure/classic/AzureSeedHostsProvider.java index 8f29dafe72fc..592c6ec0817f 100644 --- a/plugins/discovery-azure-classic/src/main/java/org/elasticsearch/discovery/azure/classic/AzureSeedHostsProvider.java +++ b/plugins/discovery-azure-classic/src/main/java/org/elasticsearch/discovery/azure/classic/AzureSeedHostsProvider.java @@ -220,15 +220,15 @@ public class AzureSeedHostsProvider implements SeedHostsProvider { return dynamicHosts; } - protected String resolveInstanceAddress(final HostType hostType, final RoleInstance instance) { - if (hostType == HostType.PRIVATE_IP) { + protected String resolveInstanceAddress(final HostType hostTypeValue, final RoleInstance instance) { + if (hostTypeValue == HostType.PRIVATE_IP) { final InetAddress privateIp = instance.getIPAddress(); if (privateIp != null) { return InetAddresses.toUriString(privateIp); } else { logger.trace("no private ip provided. ignoring [{}]...", instance.getInstanceName()); } - } else if (hostType == HostType.PUBLIC_IP) { + } else if (hostTypeValue == HostType.PUBLIC_IP) { for (InstanceEndpoint endpoint : instance.getInstanceEndpoints()) { if (publicEndpointName.equals(endpoint.getName())) { return NetworkAddress.format(new InetSocketAddress(endpoint.getVirtualIPAddress(), endpoint.getPort())); diff --git a/plugins/discovery-azure-classic/src/main/java/org/elasticsearch/plugin/discovery/azure/classic/AzureDiscoveryPlugin.java b/plugins/discovery-azure-classic/src/main/java/org/elasticsearch/plugin/discovery/azure/classic/AzureDiscoveryPlugin.java index 213fe6909f5a..c19facaf61bb 100644 --- a/plugins/discovery-azure-classic/src/main/java/org/elasticsearch/plugin/discovery/azure/classic/AzureDiscoveryPlugin.java +++ b/plugins/discovery-azure-classic/src/main/java/org/elasticsearch/plugin/discovery/azure/classic/AzureDiscoveryPlugin.java @@ -57,12 +57,12 @@ public class AzureDiscoveryPlugin extends Plugin implements DiscoveryPlugin { // Used for testing protected AzureSeedHostsProvider createSeedHostsProvider( - final Settings settings, + final Settings settingsToUse, final AzureComputeService azureComputeService, final TransportService transportService, final NetworkService networkService ) { - return new AzureSeedHostsProvider(settings, azureComputeService, transportService, networkService); + return new AzureSeedHostsProvider(settingsToUse, azureComputeService, transportService, networkService); } @Override diff --git a/plugins/discovery-ec2/src/main/java/org/elasticsearch/discovery/ec2/AwsEc2SeedHostsProvider.java b/plugins/discovery-ec2/src/main/java/org/elasticsearch/discovery/ec2/AwsEc2SeedHostsProvider.java index 25ae453d96ab..69f76ba53dbc 100644 --- a/plugins/discovery-ec2/src/main/java/org/elasticsearch/discovery/ec2/AwsEc2SeedHostsProvider.java +++ b/plugins/discovery-ec2/src/main/java/org/elasticsearch/discovery/ec2/AwsEc2SeedHostsProvider.java @@ -96,7 +96,7 @@ class AwsEc2SeedHostsProvider implements SeedHostsProvider { protected List fetchDynamicNodes() { - final List dynamicHosts = new ArrayList<>(); + final List dynamicHostAddresses = new ArrayList<>(); final DescribeInstancesResult descInstances; try (AmazonEc2Reference clientReference = awsEc2Service.client()) { @@ -109,7 +109,7 @@ class AwsEc2SeedHostsProvider implements SeedHostsProvider { } catch (final AmazonClientException e) { logger.info("Exception while retrieving instance list from AWS API: {}", e.getMessage()); logger.debug("Full exception:", e); - return dynamicHosts; + return dynamicHostAddresses; } logger.trace("finding seed nodes..."); @@ -164,8 +164,8 @@ class AwsEc2SeedHostsProvider implements SeedHostsProvider { // Reading the node host from its metadata final String tagName = hostType.substring(TAG_PREFIX.length()); logger.debug("reading hostname from [{}] instance tag", tagName); - final List tags = instance.getTags(); - for (final Tag tag : tags) { + final List tagList = instance.getTags(); + for (final Tag tag : tagList) { if (tag.getKey().equals(tagName)) { address = tag.getValue(); logger.debug("using [{}] as the instance address", address); @@ -179,7 +179,7 @@ class AwsEc2SeedHostsProvider implements SeedHostsProvider { final TransportAddress[] addresses = transportService.addressesFromString(address); for (int i = 0; i < addresses.length; i++) { logger.trace("adding {}, address {}, transport_address {}", instance.getInstanceId(), address, addresses[i]); - dynamicHosts.add(addresses[i]); + dynamicHostAddresses.add(addresses[i]); } } catch (final Exception e) { final String finalAddress = address; @@ -198,9 +198,9 @@ class AwsEc2SeedHostsProvider implements SeedHostsProvider { } } - logger.debug("using dynamic transport addresses {}", dynamicHosts); + logger.debug("using dynamic transport addresses {}", dynamicHostAddresses); - return dynamicHosts; + return dynamicHostAddresses; } private DescribeInstancesRequest buildDescribeInstancesRequest() { diff --git a/plugins/discovery-ec2/src/main/java/org/elasticsearch/discovery/ec2/AwsEc2ServiceImpl.java b/plugins/discovery-ec2/src/main/java/org/elasticsearch/discovery/ec2/AwsEc2ServiceImpl.java index f8dff105f564..26c235fb258a 100644 --- a/plugins/discovery-ec2/src/main/java/org/elasticsearch/discovery/ec2/AwsEc2ServiceImpl.java +++ b/plugins/discovery-ec2/src/main/java/org/elasticsearch/discovery/ec2/AwsEc2ServiceImpl.java @@ -28,14 +28,14 @@ import java.util.concurrent.atomic.AtomicReference; class AwsEc2ServiceImpl implements AwsEc2Service { - private static final Logger logger = LogManager.getLogger(AwsEc2ServiceImpl.class); + private static final Logger LOGGER = LogManager.getLogger(AwsEc2ServiceImpl.class); private final AtomicReference> lazyClientReference = new AtomicReference<>(); private AmazonEC2 buildClient(Ec2ClientSettings clientSettings) { - final AWSCredentialsProvider credentials = buildCredentials(logger, clientSettings); - final ClientConfiguration configuration = buildConfiguration(logger, clientSettings); + final AWSCredentialsProvider credentials = buildCredentials(LOGGER, clientSettings); + final ClientConfiguration configuration = buildConfiguration(LOGGER, clientSettings); return buildClient(credentials, configuration, clientSettings.endpoint); } @@ -45,7 +45,7 @@ class AwsEc2ServiceImpl implements AwsEc2Service { .withCredentials(credentials) .withClientConfiguration(configuration); if (Strings.hasText(endpoint)) { - logger.debug("using explicit ec2 endpoint [{}]", endpoint); + LOGGER.debug("using explicit ec2 endpoint [{}]", endpoint); builder.withEndpointConfiguration(new AwsClientBuilder.EndpointConfiguration(endpoint, null)); } return SocketAccess.doPrivileged(builder::build); diff --git a/plugins/discovery-ec2/src/main/java/org/elasticsearch/discovery/ec2/Ec2DiscoveryPlugin.java b/plugins/discovery-ec2/src/main/java/org/elasticsearch/discovery/ec2/Ec2DiscoveryPlugin.java index 91ab319b121e..81462647d9a3 100644 --- a/plugins/discovery-ec2/src/main/java/org/elasticsearch/discovery/ec2/Ec2DiscoveryPlugin.java +++ b/plugins/discovery-ec2/src/main/java/org/elasticsearch/discovery/ec2/Ec2DiscoveryPlugin.java @@ -43,7 +43,7 @@ import java.util.function.Supplier; public class Ec2DiscoveryPlugin extends Plugin implements DiscoveryPlugin, ReloadablePlugin { - private static Logger logger = LogManager.getLogger(Ec2DiscoveryPlugin.class); + private static final Logger logger = LogManager.getLogger(Ec2DiscoveryPlugin.class); public static final String EC2 = "ec2"; static { @@ -80,7 +80,7 @@ public class Ec2DiscoveryPlugin extends Plugin implements DiscoveryPlugin, Reloa } @Override - public NetworkService.CustomNameResolver getCustomNameResolver(Settings settings) { + public NetworkService.CustomNameResolver getCustomNameResolver(Settings _settings) { logger.debug("Register _ec2_, _ec2:xxx_ network names"); return new Ec2NameResolver(); } @@ -171,9 +171,9 @@ public class Ec2DiscoveryPlugin extends Plugin implements DiscoveryPlugin, Reloa } @Override - public void reload(Settings settings) { + public void reload(Settings settingsToLoad) { // secure settings should be readable - final Ec2ClientSettings clientSettings = Ec2ClientSettings.getClientSettings(settings); + final Ec2ClientSettings clientSettings = Ec2ClientSettings.getClientSettings(settingsToLoad); ec2Service.refreshAndClearCache(clientSettings); } } diff --git a/plugins/discovery-gce/src/main/java/org/elasticsearch/plugin/discovery/gce/GceDiscoveryPlugin.java b/plugins/discovery-gce/src/main/java/org/elasticsearch/plugin/discovery/gce/GceDiscoveryPlugin.java index 268fdde4ca5a..114fc4fbcc49 100644 --- a/plugins/discovery-gce/src/main/java/org/elasticsearch/plugin/discovery/gce/GceDiscoveryPlugin.java +++ b/plugins/discovery-gce/src/main/java/org/elasticsearch/plugin/discovery/gce/GceDiscoveryPlugin.java @@ -83,14 +83,14 @@ public class GceDiscoveryPlugin extends Plugin implements DiscoveryPlugin, Close } @Override - public NetworkService.CustomNameResolver getCustomNameResolver(Settings settings) { + public NetworkService.CustomNameResolver getCustomNameResolver(Settings settingsToUse) { logger.debug("Register _gce_, _gce:xxx network names"); - return new GceNameResolver(new GceMetadataService(settings)); + return new GceNameResolver(new GceMetadataService(settingsToUse)); } @Override public List> getSettings() { - List> settings = new ArrayList<>( + List> settingList = new ArrayList<>( Arrays.asList( // Register GCE settings GceInstancesService.PROJECT_SETTING, @@ -103,10 +103,10 @@ public class GceDiscoveryPlugin extends Plugin implements DiscoveryPlugin, Close ); if (ALLOW_REROUTE_GCE_SETTINGS) { - settings.add(GceMetadataService.GCE_HOST); - settings.add(GceInstancesServiceImpl.GCE_ROOT_URL); + settingList.add(GceMetadataService.GCE_HOST); + settingList.add(GceInstancesServiceImpl.GCE_ROOT_URL); } - return Collections.unmodifiableList(settings); + return Collections.unmodifiableList(settingList); } @Override diff --git a/plugins/ingest-attachment/src/main/java/org/elasticsearch/ingest/attachment/AttachmentProcessor.java b/plugins/ingest-attachment/src/main/java/org/elasticsearch/ingest/attachment/AttachmentProcessor.java index 287f3f42e967..6a7ad59bb7c5 100644 --- a/plugins/ingest-attachment/src/main/java/org/elasticsearch/ingest/attachment/AttachmentProcessor.java +++ b/plugins/ingest-attachment/src/main/java/org/elasticsearch/ingest/attachment/AttachmentProcessor.java @@ -87,14 +87,14 @@ public final class AttachmentProcessor extends AbstractProcessor { throw new IllegalArgumentException("field [" + field + "] is null, cannot parse."); } - Integer indexedChars = this.indexedChars; + Integer indexedCharsValue = this.indexedChars; if (indexedCharsField != null) { // If the user provided the number of characters to be extracted as part of the document, we use it - indexedChars = ingestDocument.getFieldValue(indexedCharsField, Integer.class, true); - if (indexedChars == null) { + indexedCharsValue = ingestDocument.getFieldValue(indexedCharsField, Integer.class, true); + if (indexedCharsValue == null) { // If the field does not exist we fall back to the global limit - indexedChars = this.indexedChars; + indexedCharsValue = this.indexedChars; } } @@ -104,7 +104,7 @@ public final class AttachmentProcessor extends AbstractProcessor { } String parsedContent = ""; try { - parsedContent = TikaImpl.parse(input, metadata, indexedChars); + parsedContent = TikaImpl.parse(input, metadata, indexedCharsValue); } catch (ZeroByteFileException e) { // tika 1.17 throws an exception when the InputStream has 0 bytes. // previously, it did not mind. This is here to preserve that behavior. diff --git a/plugins/ingest-attachment/src/test/java/org/elasticsearch/ingest/attachment/AttachmentProcessorTests.java b/plugins/ingest-attachment/src/test/java/org/elasticsearch/ingest/attachment/AttachmentProcessorTests.java index 9f4ca8ae3872..391eb403054d 100644 --- a/plugins/ingest-attachment/src/test/java/org/elasticsearch/ingest/attachment/AttachmentProcessorTests.java +++ b/plugins/ingest-attachment/src/test/java/org/elasticsearch/ingest/attachment/AttachmentProcessorTests.java @@ -39,7 +39,7 @@ import static org.hamcrest.Matchers.nullValue; public class AttachmentProcessorTests extends ESTestCase { - private AttachmentProcessor processor; + private Processor processor; @Before public void createStandardProcessor() { @@ -263,17 +263,7 @@ public class AttachmentProcessorTests extends ESTestCase { Collections.singletonMap("source_field", null) ); IngestDocument ingestDocument = new IngestDocument(originalIngestDocument); - Processor processor = new AttachmentProcessor( - randomAlphaOfLength(10), - null, - "source_field", - "randomTarget", - null, - 10, - true, - null, - null - ); + processor = new AttachmentProcessor(randomAlphaOfLength(10), null, "source_field", "randomTarget", null, 10, true, null, null); processor.execute(ingestDocument); assertIngestDocument(originalIngestDocument, ingestDocument); } @@ -281,17 +271,7 @@ public class AttachmentProcessorTests extends ESTestCase { public void testNonExistentWithIgnoreMissing() throws Exception { IngestDocument originalIngestDocument = RandomDocumentPicks.randomIngestDocument(random(), Collections.emptyMap()); IngestDocument ingestDocument = new IngestDocument(originalIngestDocument); - Processor processor = new AttachmentProcessor( - randomAlphaOfLength(10), - null, - "source_field", - "randomTarget", - null, - 10, - true, - null, - null - ); + processor = new AttachmentProcessor(randomAlphaOfLength(10), null, "source_field", "randomTarget", null, 10, true, null, null); processor.execute(ingestDocument); assertIngestDocument(originalIngestDocument, ingestDocument); } @@ -302,17 +282,7 @@ public class AttachmentProcessorTests extends ESTestCase { Collections.singletonMap("source_field", null) ); IngestDocument ingestDocument = new IngestDocument(originalIngestDocument); - Processor processor = new AttachmentProcessor( - randomAlphaOfLength(10), - null, - "source_field", - "randomTarget", - null, - 10, - false, - null, - null - ); + processor = new AttachmentProcessor(randomAlphaOfLength(10), null, "source_field", "randomTarget", null, 10, false, null, null); Exception exception = expectThrows(Exception.class, () -> processor.execute(ingestDocument)); assertThat(exception.getMessage(), equalTo("field [source_field] is null, cannot parse.")); } @@ -320,33 +290,23 @@ public class AttachmentProcessorTests extends ESTestCase { public void testNonExistentWithoutIgnoreMissing() throws Exception { IngestDocument originalIngestDocument = RandomDocumentPicks.randomIngestDocument(random(), Collections.emptyMap()); IngestDocument ingestDocument = new IngestDocument(originalIngestDocument); - Processor processor = new AttachmentProcessor( - randomAlphaOfLength(10), - null, - "source_field", - "randomTarget", - null, - 10, - false, - null, - null - ); + processor = new AttachmentProcessor(randomAlphaOfLength(10), null, "source_field", "randomTarget", null, 10, false, null, null); Exception exception = expectThrows(Exception.class, () -> processor.execute(ingestDocument)); assertThat(exception.getMessage(), equalTo("field [source_field] not present as part of path [source_field]")); } - private Map parseDocument(String file, AttachmentProcessor processor) throws Exception { - return parseDocument(file, processor, new HashMap<>()); + private Map parseDocument(String file, Processor attachmentProcessor) throws Exception { + return parseDocument(file, attachmentProcessor, new HashMap<>()); } - private Map parseDocument(String file, AttachmentProcessor processor, Map optionalFields) + private Map parseDocument(String file, Processor attachmentProcessor, Map optionalFields) throws Exception { - return parseDocument(file, processor, optionalFields, false); + return parseDocument(file, attachmentProcessor, optionalFields, false); } private Map parseDocument( String file, - AttachmentProcessor processor, + Processor attachmentProcessor, Map optionalFields, boolean includeResourceName ) throws Exception { @@ -358,7 +318,7 @@ public class AttachmentProcessorTests extends ESTestCase { document.putAll(optionalFields); IngestDocument ingestDocument = RandomDocumentPicks.randomIngestDocument(random(), document); - processor.execute(ingestDocument); + attachmentProcessor.execute(ingestDocument); @SuppressWarnings("unchecked") Map attachmentData = (Map) ingestDocument.getSourceAndMetadata().get("target_field"); diff --git a/plugins/mapper-annotated-text/src/main/java/org/elasticsearch/index/mapper/annotatedtext/AnnotatedPassageFormatter.java b/plugins/mapper-annotated-text/src/main/java/org/elasticsearch/index/mapper/annotatedtext/AnnotatedPassageFormatter.java index 557581ef0309..db701b65a576 100644 --- a/plugins/mapper-annotated-text/src/main/java/org/elasticsearch/index/mapper/annotatedtext/AnnotatedPassageFormatter.java +++ b/plugins/mapper-annotated-text/src/main/java/org/elasticsearch/index/mapper/annotatedtext/AnnotatedPassageFormatter.java @@ -160,8 +160,8 @@ public class AnnotatedPassageFormatter extends PassageFormatter { int pos; int j = 0; for (Passage passage : passages) { - AnnotationToken[] annotations = getIntersectingAnnotations(passage.getStartOffset(), passage.getEndOffset()); - MarkupPassage mergedMarkup = mergeAnnotations(annotations, passage); + AnnotationToken[] annotationTokens = getIntersectingAnnotations(passage.getStartOffset(), passage.getEndOffset()); + MarkupPassage mergedMarkup = mergeAnnotations(annotationTokens, passage); StringBuilder sb = new StringBuilder(); pos = passage.getStartOffset(); diff --git a/plugins/mapper-annotated-text/src/main/java/org/elasticsearch/index/mapper/annotatedtext/AnnotatedTextFieldMapper.java b/plugins/mapper-annotated-text/src/main/java/org/elasticsearch/index/mapper/annotatedtext/AnnotatedTextFieldMapper.java index a68f4ed1e4e7..c86172f075b7 100644 --- a/plugins/mapper-annotated-text/src/main/java/org/elasticsearch/index/mapper/annotatedtext/AnnotatedTextFieldMapper.java +++ b/plugins/mapper-annotated-text/src/main/java/org/elasticsearch/index/mapper/annotatedtext/AnnotatedTextFieldMapper.java @@ -393,11 +393,11 @@ public class AnnotatedTextFieldMapper extends FieldMapper { super(in); } - public void setAnnotations(AnnotatedText annotatedText) { - this.annotatedText = annotatedText; + public void setAnnotations(AnnotatedText text) { + this.annotatedText = text; currentAnnotationIndex = 0; - if (annotatedText != null && annotatedText.numAnnotations() > 0) { - nextAnnotationForInjection = annotatedText.getAnnotation(0); + if (text != null && text.numAnnotations() > 0) { + nextAnnotationForInjection = text.getAnnotation(0); } else { nextAnnotationForInjection = null; } diff --git a/plugins/repository-azure/src/internalClusterTest/java/org/elasticsearch/repositories/azure/AzureBlobStoreRepositoryTests.java b/plugins/repository-azure/src/internalClusterTest/java/org/elasticsearch/repositories/azure/AzureBlobStoreRepositoryTests.java index 7941d1c44f0b..93427605ea63 100644 --- a/plugins/repository-azure/src/internalClusterTest/java/org/elasticsearch/repositories/azure/AzureBlobStoreRepositoryTests.java +++ b/plugins/repository-azure/src/internalClusterTest/java/org/elasticsearch/repositories/azure/AzureBlobStoreRepositoryTests.java @@ -114,8 +114,8 @@ public class AzureBlobStoreRepositoryTests extends ESMockAPIBasedRepositoryInteg } @Override - AzureStorageService createAzureStorageService(Settings settings, AzureClientProvider azureClientProvider) { - return new AzureStorageService(settings, azureClientProvider) { + AzureStorageService createAzureStorageService(Settings settingsToUse, AzureClientProvider azureClientProvider) { + return new AzureStorageService(settingsToUse, azureClientProvider) { @Override RequestRetryOptions getRetryOptions(LocationMode locationMode, AzureStorageSettings azureStorageSettings) { return new RequestRetryOptions( diff --git a/plugins/repository-azure/src/main/java/org/elasticsearch/repositories/azure/AzureBlobStore.java b/plugins/repository-azure/src/main/java/org/elasticsearch/repositories/azure/AzureBlobStore.java index 2033c897f47f..3de402ec34d9 100644 --- a/plugins/repository-azure/src/main/java/org/elasticsearch/repositories/azure/AzureBlobStore.java +++ b/plugins/repository-azure/src/main/java/org/elasticsearch/repositories/azure/AzureBlobStore.java @@ -700,9 +700,9 @@ public class AzureBlobStore implements BlobStore { } private ByteBuf copyBuffer(ByteBuffer buffer) { - ByteBuf byteBuf = allocator.heapBuffer(buffer.remaining(), buffer.remaining()); - byteBuf.writeBytes(buffer); - return byteBuf; + ByteBuf byteBuffer = allocator.heapBuffer(buffer.remaining(), buffer.remaining()); + byteBuffer.writeBytes(buffer); + return byteBuffer; } @Override diff --git a/plugins/repository-azure/src/main/java/org/elasticsearch/repositories/azure/AzureRepositoryPlugin.java b/plugins/repository-azure/src/main/java/org/elasticsearch/repositories/azure/AzureRepositoryPlugin.java index ce66aa9bffc1..b44c1e537a1a 100644 --- a/plugins/repository-azure/src/main/java/org/elasticsearch/repositories/azure/AzureRepositoryPlugin.java +++ b/plugins/repository-azure/src/main/java/org/elasticsearch/repositories/azure/AzureRepositoryPlugin.java @@ -100,8 +100,8 @@ public class AzureRepositoryPlugin extends Plugin implements RepositoryPlugin, R return Collections.singletonList(azureClientProvider); } - AzureStorageService createAzureStorageService(Settings settings, AzureClientProvider azureClientProvider) { - return new AzureStorageService(settings, azureClientProvider); + AzureStorageService createAzureStorageService(Settings settingsToUse, AzureClientProvider azureClientProvider) { + return new AzureStorageService(settingsToUse, azureClientProvider); } @Override @@ -120,8 +120,8 @@ public class AzureRepositoryPlugin extends Plugin implements RepositoryPlugin, R } @Override - public List> getExecutorBuilders(Settings settings) { - return Arrays.asList(executorBuilder(), nettyEventLoopExecutorBuilder(settings)); + public List> getExecutorBuilders(Settings settingsToUse) { + return Arrays.asList(executorBuilder(), nettyEventLoopExecutorBuilder(settingsToUse)); } public static ExecutorBuilder executorBuilder() { @@ -134,9 +134,9 @@ public class AzureRepositoryPlugin extends Plugin implements RepositoryPlugin, R } @Override - public void reload(Settings settings) { + public void reload(Settings settingsToLoad) { // secure settings should be readable - final Map clientsSettings = AzureStorageSettings.load(settings); + final Map clientsSettings = AzureStorageSettings.load(settingsToLoad); AzureStorageService storageService = azureStoreService.get(); assert storageService != null; storageService.refreshSettings(clientsSettings); diff --git a/plugins/repository-gcs/src/internalClusterTest/java/org/elasticsearch/repositories/gcs/GoogleCloudStorageBlobStoreRepositoryTests.java b/plugins/repository-gcs/src/internalClusterTest/java/org/elasticsearch/repositories/gcs/GoogleCloudStorageBlobStoreRepositoryTests.java index 732d8896401f..aad9175c3435 100644 --- a/plugins/repository-gcs/src/internalClusterTest/java/org/elasticsearch/repositories/gcs/GoogleCloudStorageBlobStoreRepositoryTests.java +++ b/plugins/repository-gcs/src/internalClusterTest/java/org/elasticsearch/repositories/gcs/GoogleCloudStorageBlobStoreRepositoryTests.java @@ -237,10 +237,10 @@ public class GoogleCloudStorageBlobStoreRepositoryTests extends ESMockAPIBasedRe return new GoogleCloudStorageService() { @Override StorageOptions createStorageOptions( - final GoogleCloudStorageClientSettings clientSettings, + final GoogleCloudStorageClientSettings gcsClientSettings, final HttpTransportOptions httpTransportOptions ) { - StorageOptions options = super.createStorageOptions(clientSettings, httpTransportOptions); + StorageOptions options = super.createStorageOptions(gcsClientSettings, httpTransportOptions); return options.toBuilder() .setHost(options.getHost()) .setCredentials(options.getCredentials()) diff --git a/plugins/repository-gcs/src/main/java/org/elasticsearch/repositories/gcs/GoogleCloudStorageService.java b/plugins/repository-gcs/src/main/java/org/elasticsearch/repositories/gcs/GoogleCloudStorageService.java index 57bbd4495f8d..0534a244fbf7 100644 --- a/plugins/repository-gcs/src/main/java/org/elasticsearch/repositories/gcs/GoogleCloudStorageService.java +++ b/plugins/repository-gcs/src/main/java/org/elasticsearch/repositories/gcs/GoogleCloudStorageService.java @@ -121,12 +121,12 @@ public class GoogleCloudStorageService { /** * Creates a client that can be used to manage Google Cloud Storage objects. The client is thread-safe. * - * @param clientSettings client settings to use, including secure settings + * @param gcsClientSettings client settings to use, including secure settings * @param stats the stats collector to use by the underlying SDK * @return a new client storage instance that can be used to manage objects * (blobs) */ - private Storage createClient(GoogleCloudStorageClientSettings clientSettings, GoogleCloudStorageOperationsStats stats) + private Storage createClient(GoogleCloudStorageClientSettings gcsClientSettings, GoogleCloudStorageOperationsStats stats) throws IOException { final HttpTransport httpTransport = SocketAccess.doPrivilegedIOException(() -> { final NetHttpTransport.Builder builder = new NetHttpTransport.Builder(); @@ -146,8 +146,8 @@ public class GoogleCloudStorageService { final HttpTransportOptions httpTransportOptions = new HttpTransportOptions( HttpTransportOptions.newBuilder() - .setConnectTimeout(toTimeout(clientSettings.getConnectTimeout())) - .setReadTimeout(toTimeout(clientSettings.getReadTimeout())) + .setConnectTimeout(toTimeout(gcsClientSettings.getConnectTimeout())) + .setReadTimeout(toTimeout(gcsClientSettings.getReadTimeout())) .setHttpTransportFactory(() -> httpTransport) ) { @@ -163,28 +163,28 @@ public class GoogleCloudStorageService { } }; - final StorageOptions storageOptions = createStorageOptions(clientSettings, httpTransportOptions); + final StorageOptions storageOptions = createStorageOptions(gcsClientSettings, httpTransportOptions); return storageOptions.getService(); } StorageOptions createStorageOptions( - final GoogleCloudStorageClientSettings clientSettings, + final GoogleCloudStorageClientSettings gcsClientSettings, final HttpTransportOptions httpTransportOptions ) { final StorageOptions.Builder storageOptionsBuilder = StorageOptions.newBuilder() .setTransportOptions(httpTransportOptions) .setHeaderProvider(() -> { final MapBuilder mapBuilder = MapBuilder.newMapBuilder(); - if (Strings.hasLength(clientSettings.getApplicationName())) { - mapBuilder.put("user-agent", clientSettings.getApplicationName()); + if (Strings.hasLength(gcsClientSettings.getApplicationName())) { + mapBuilder.put("user-agent", gcsClientSettings.getApplicationName()); } return mapBuilder.immutableMap(); }); - if (Strings.hasLength(clientSettings.getHost())) { - storageOptionsBuilder.setHost(clientSettings.getHost()); + if (Strings.hasLength(gcsClientSettings.getHost())) { + storageOptionsBuilder.setHost(gcsClientSettings.getHost()); } - if (Strings.hasLength(clientSettings.getProjectId())) { - storageOptionsBuilder.setProjectId(clientSettings.getProjectId()); + if (Strings.hasLength(gcsClientSettings.getProjectId())) { + storageOptionsBuilder.setProjectId(gcsClientSettings.getProjectId()); } else { String defaultProjectId = null; try { @@ -210,16 +210,16 @@ public class GoogleCloudStorageService { } } } - if (clientSettings.getCredential() == null) { + if (gcsClientSettings.getCredential() == null) { try { storageOptionsBuilder.setCredentials(GoogleCredentials.getApplicationDefault()); } catch (Exception e) { logger.warn("failed to load Application Default Credentials", e); } } else { - ServiceAccountCredentials serviceAccountCredentials = clientSettings.getCredential(); + ServiceAccountCredentials serviceAccountCredentials = gcsClientSettings.getCredential(); // override token server URI - final URI tokenServerUri = clientSettings.getTokenUri(); + final URI tokenServerUri = gcsClientSettings.getTokenUri(); if (Strings.hasLength(tokenServerUri.toString())) { // Rebuild the service account credentials in order to use a custom Token url. // This is mostly used for testing purpose. diff --git a/plugins/repository-gcs/src/test/java/org/elasticsearch/repositories/gcs/GoogleCloudStorageBlobContainerRetriesTests.java b/plugins/repository-gcs/src/test/java/org/elasticsearch/repositories/gcs/GoogleCloudStorageBlobContainerRetriesTests.java index 40c3c89ed1e2..5618a3ab91ef 100644 --- a/plugins/repository-gcs/src/test/java/org/elasticsearch/repositories/gcs/GoogleCloudStorageBlobContainerRetriesTests.java +++ b/plugins/repository-gcs/src/test/java/org/elasticsearch/repositories/gcs/GoogleCloudStorageBlobContainerRetriesTests.java @@ -140,10 +140,10 @@ public class GoogleCloudStorageBlobContainerRetriesTests extends AbstractBlobCon final GoogleCloudStorageService service = new GoogleCloudStorageService() { @Override StorageOptions createStorageOptions( - final GoogleCloudStorageClientSettings clientSettings, + final GoogleCloudStorageClientSettings gcsClientSettings, final HttpTransportOptions httpTransportOptions ) { - StorageOptions options = super.createStorageOptions(clientSettings, httpTransportOptions); + StorageOptions options = super.createStorageOptions(gcsClientSettings, httpTransportOptions); RetrySettings.Builder retrySettingsBuilder = RetrySettings.newBuilder() .setTotalTimeout(options.getRetrySettings().getTotalTimeout()) .setInitialRetryDelay(Duration.ofMillis(10L)) diff --git a/plugins/repository-hdfs/src/main/java/org/elasticsearch/repositories/hdfs/HdfsBlobContainer.java b/plugins/repository-hdfs/src/main/java/org/elasticsearch/repositories/hdfs/HdfsBlobContainer.java index 7ffb03b5a032..7e75959bedb8 100644 --- a/plugins/repository-hdfs/src/main/java/org/elasticsearch/repositories/hdfs/HdfsBlobContainer.java +++ b/plugins/repository-hdfs/src/main/java/org/elasticsearch/repositories/hdfs/HdfsBlobContainer.java @@ -235,7 +235,7 @@ final class HdfsBlobContainer extends AbstractBlobContainer { FileStatus[] files; try { files = store.execute( - fileContext -> fileContext.util().listStatus(path, path -> prefix == null || path.getName().startsWith(prefix)) + fileContext -> fileContext.util().listStatus(path, eachPath -> prefix == null || eachPath.getName().startsWith(prefix)) ); } catch (FileNotFoundException e) { files = new FileStatus[0]; diff --git a/plugins/repository-hdfs/src/main/java/org/elasticsearch/repositories/hdfs/HdfsBlobStore.java b/plugins/repository-hdfs/src/main/java/org/elasticsearch/repositories/hdfs/HdfsBlobStore.java index a4708efaae9b..29e679b65cb3 100644 --- a/plugins/repository-hdfs/src/main/java/org/elasticsearch/repositories/hdfs/HdfsBlobStore.java +++ b/plugins/repository-hdfs/src/main/java/org/elasticsearch/repositories/hdfs/HdfsBlobStore.java @@ -48,6 +48,7 @@ final class HdfsBlobStore implements BlobStore { } } + @SuppressWarnings("HiddenField") private void mkdirs(Path path) throws IOException { execute((Operation) fileContext -> { fileContext.mkdir(path, null, true); diff --git a/plugins/repository-hdfs/src/main/java/org/elasticsearch/repositories/hdfs/HdfsRepository.java b/plugins/repository-hdfs/src/main/java/org/elasticsearch/repositories/hdfs/HdfsRepository.java index 30ee065237a2..60f534227c42 100644 --- a/plugins/repository-hdfs/src/main/java/org/elasticsearch/repositories/hdfs/HdfsRepository.java +++ b/plugins/repository-hdfs/src/main/java/org/elasticsearch/repositories/hdfs/HdfsRepository.java @@ -106,7 +106,7 @@ public final class HdfsRepository extends BlobStoreRepository { } } - private HdfsBlobStore createBlobstore(URI uri, String path, Settings repositorySettings) { + private HdfsBlobStore createBlobstore(URI blobstoreUri, String path, Settings repositorySettings) { Configuration hadoopConfiguration = new Configuration(repositorySettings.getAsBoolean("load_defaults", true)); hadoopConfiguration.setClassLoader(HdfsRepository.class.getClassLoader()); hadoopConfiguration.reloadConfiguration(); @@ -126,7 +126,7 @@ public final class HdfsRepository extends BlobStoreRepository { // Sense if HA is enabled // HA requires elevated permissions during regular usage in the event that a failover operation // occurs and a new connection is required. - String host = uri.getHost(); + String host = blobstoreUri.getHost(); String configKey = HdfsClientConfigKeys.Failover.PROXY_PROVIDER_KEY_PREFIX + "." + host; Class ret = hadoopConfiguration.getClass(configKey, null, FailoverProxyProvider.class); boolean haEnabled = ret != null; @@ -135,7 +135,7 @@ public final class HdfsRepository extends BlobStoreRepository { // This will correctly configure the filecontext to have our UGI as its internal user. FileContext fileContext = ugi.doAs((PrivilegedAction) () -> { try { - AbstractFileSystem fs = AbstractFileSystem.get(uri, hadoopConfiguration); + AbstractFileSystem fs = AbstractFileSystem.get(blobstoreUri, hadoopConfiguration); return FileContext.getFileContext(fs, hadoopConfiguration); } catch (UnsupportedFileSystemException e) { throw new UncheckedIOException(e); @@ -152,7 +152,7 @@ public final class HdfsRepository extends BlobStoreRepository { try { return new HdfsBlobStore(fileContext, path, bufferSize, isReadOnly(), haEnabled); } catch (IOException e) { - throw new UncheckedIOException(String.format(Locale.ROOT, "Cannot create HDFS repository for uri [%s]", uri), e); + throw new UncheckedIOException(String.format(Locale.ROOT, "Cannot create HDFS repository for uri [%s]", blobstoreUri), e); } } diff --git a/plugins/repository-hdfs/src/main/java/org/elasticsearch/repositories/hdfs/HdfsSecurityContext.java b/plugins/repository-hdfs/src/main/java/org/elasticsearch/repositories/hdfs/HdfsSecurityContext.java index 2cd6ccadd096..630afc8f1828 100644 --- a/plugins/repository-hdfs/src/main/java/org/elasticsearch/repositories/hdfs/HdfsSecurityContext.java +++ b/plugins/repository-hdfs/src/main/java/org/elasticsearch/repositories/hdfs/HdfsSecurityContext.java @@ -100,9 +100,9 @@ class HdfsSecurityContext { this.restrictedExecutionPermissions = renderPermissions(ugi); } - private Permission[] renderPermissions(UserGroupInformation ugi) { + private Permission[] renderPermissions(UserGroupInformation userGroupInformation) { Permission[] permissions; - if (ugi.isFromKeytab()) { + if (userGroupInformation.isFromKeytab()) { // KERBEROS // Leave room to append one extra permission based on the logged in user's info. int permlen = KERBEROS_AUTH_PERMISSIONS.length + 1; @@ -112,7 +112,7 @@ class HdfsSecurityContext { // Append a kerberos.ServicePermission to only allow initiating kerberos connections // as the logged in user. - permissions[permissions.length - 1] = new ServicePermission(ugi.getUserName(), "initiate"); + permissions[permissions.length - 1] = new ServicePermission(userGroupInformation.getUserName(), "initiate"); } else { // SIMPLE permissions = Arrays.copyOf(SIMPLE_AUTH_PERMISSIONS, SIMPLE_AUTH_PERMISSIONS.length); diff --git a/plugins/repository-s3/src/main/java/org/elasticsearch/repositories/s3/S3BlobContainer.java b/plugins/repository-s3/src/main/java/org/elasticsearch/repositories/s3/S3BlobContainer.java index f415c3f64ae9..e71c78ee09a7 100644 --- a/plugins/repository-s3/src/main/java/org/elasticsearch/repositories/s3/S3BlobContainer.java +++ b/plugins/repository-s3/src/main/java/org/elasticsearch/repositories/s3/S3BlobContainer.java @@ -451,9 +451,9 @@ class S3BlobContainer extends AbstractBlobContainer { return results; } - private ListObjectsRequest listObjectsRequest(String keyPath) { + private ListObjectsRequest listObjectsRequest(String pathPrefix) { return new ListObjectsRequest().withBucketName(blobStore.bucket()) - .withPrefix(keyPath) + .withPrefix(pathPrefix) .withDelimiter("/") .withRequestMetricCollector(blobStore.listMetricCollector); } @@ -465,28 +465,28 @@ class S3BlobContainer extends AbstractBlobContainer { /** * Uploads a blob using a single upload request */ - void executeSingleUpload(final S3BlobStore blobStore, final String blobName, final InputStream input, final long blobSize) + void executeSingleUpload(final S3BlobStore s3BlobStore, final String blobName, final InputStream input, final long blobSize) throws IOException { // Extra safety checks if (blobSize > MAX_FILE_SIZE.getBytes()) { throw new IllegalArgumentException("Upload request size [" + blobSize + "] can't be larger than " + MAX_FILE_SIZE); } - if (blobSize > blobStore.bufferSizeInBytes()) { + if (blobSize > s3BlobStore.bufferSizeInBytes()) { throw new IllegalArgumentException("Upload request size [" + blobSize + "] can't be larger than buffer size"); } final ObjectMetadata md = new ObjectMetadata(); md.setContentLength(blobSize); - if (blobStore.serverSideEncryption()) { + if (s3BlobStore.serverSideEncryption()) { md.setSSEAlgorithm(ObjectMetadata.AES_256_SERVER_SIDE_ENCRYPTION); } - final PutObjectRequest putRequest = new PutObjectRequest(blobStore.bucket(), blobName, input, md); - putRequest.setStorageClass(blobStore.getStorageClass()); - putRequest.setCannedAcl(blobStore.getCannedACL()); - putRequest.setRequestMetricCollector(blobStore.putMetricCollector); + final PutObjectRequest putRequest = new PutObjectRequest(s3BlobStore.bucket(), blobName, input, md); + putRequest.setStorageClass(s3BlobStore.getStorageClass()); + putRequest.setCannedAcl(s3BlobStore.getCannedACL()); + putRequest.setRequestMetricCollector(s3BlobStore.putMetricCollector); - try (AmazonS3Reference clientReference = blobStore.clientReference()) { + try (AmazonS3Reference clientReference = s3BlobStore.clientReference()) { SocketAccess.doPrivilegedVoid(() -> { clientReference.client().putObject(putRequest); }); } catch (final AmazonClientException e) { throw new IOException("Unable to upload object [" + blobName + "] using a single upload", e); @@ -496,11 +496,11 @@ class S3BlobContainer extends AbstractBlobContainer { /** * Uploads a blob using multipart upload requests. */ - void executeMultipartUpload(final S3BlobStore blobStore, final String blobName, final InputStream input, final long blobSize) + void executeMultipartUpload(final S3BlobStore s3BlobStore, final String blobName, final InputStream input, final long blobSize) throws IOException { ensureMultiPartUploadSize(blobSize); - final long partSize = blobStore.bufferSizeInBytes(); + final long partSize = s3BlobStore.bufferSizeInBytes(); final Tuple multiparts = numberOfMultiparts(blobSize, partSize); if (multiparts.v1() > Integer.MAX_VALUE) { @@ -512,9 +512,9 @@ class S3BlobContainer extends AbstractBlobContainer { assert blobSize == (((nbParts - 1) * partSize) + lastPartSize) : "blobSize does not match multipart sizes"; final SetOnce uploadId = new SetOnce<>(); - final String bucketName = blobStore.bucket(); + final String bucketName = s3BlobStore.bucket(); boolean success = false; - try (AmazonS3Reference clientReference = blobStore.clientReference()) { + try (AmazonS3Reference clientReference = s3BlobStore.clientReference()) { uploadId.set( SocketAccess.doPrivileged( @@ -556,7 +556,7 @@ class S3BlobContainer extends AbstractBlobContainer { uploadId.get(), parts ); - complRequest.setRequestMetricCollector(blobStore.multiPartUploadMetricCollector); + complRequest.setRequestMetricCollector(s3BlobStore.multiPartUploadMetricCollector); SocketAccess.doPrivilegedVoid(() -> clientReference.client().completeMultipartUpload(complRequest)); success = true; diff --git a/plugins/repository-s3/src/main/java/org/elasticsearch/repositories/s3/S3Service.java b/plugins/repository-s3/src/main/java/org/elasticsearch/repositories/s3/S3Service.java index 0a8b85e16513..86b1b2d81055 100644 --- a/plugins/repository-s3/src/main/java/org/elasticsearch/repositories/s3/S3Service.java +++ b/plugins/repository-s3/src/main/java/org/elasticsearch/repositories/s3/S3Service.java @@ -32,7 +32,7 @@ import java.util.Map; import static java.util.Collections.emptyMap; class S3Service implements Closeable { - private static final Logger logger = LogManager.getLogger(S3Service.class); + private static final Logger LOGGER = LogManager.getLogger(S3Service.class); private volatile Map clientsCache = emptyMap(); @@ -127,7 +127,7 @@ class S3Service implements Closeable { // proxy for testing AmazonS3 buildClient(final S3ClientSettings clientSettings) { final AmazonS3ClientBuilder builder = AmazonS3ClientBuilder.standard(); - builder.withCredentials(buildCredentials(logger, clientSettings)); + builder.withCredentials(buildCredentials(LOGGER, clientSettings)); builder.withClientConfiguration(buildConfiguration(clientSettings)); String endpoint = Strings.hasLength(clientSettings.endpoint) ? clientSettings.endpoint : Constants.S3_HOSTNAME; @@ -137,7 +137,7 @@ class S3Service implements Closeable { endpoint = clientSettings.protocol.toString() + "://" + endpoint; } final String region = Strings.hasLength(clientSettings.region) ? clientSettings.region : null; - logger.debug("using endpoint [{}] and region [{}]", endpoint, region); + LOGGER.debug("using endpoint [{}] and region [{}]", endpoint, region); // If the endpoint configuration isn't set on the builder then the default behaviour is to try // and work out what region we are in and use an appropriate endpoint - see AwsClientBuilder#setRegion. diff --git a/plugins/transport-nio/src/main/java/org/elasticsearch/http/nio/NioHttpRequest.java b/plugins/transport-nio/src/main/java/org/elasticsearch/http/nio/NioHttpRequest.java index 77bb0468a0a4..56e12c063ee0 100644 --- a/plugins/transport-nio/src/main/java/org/elasticsearch/http/nio/NioHttpRequest.java +++ b/plugins/transport-nio/src/main/java/org/elasticsearch/http/nio/NioHttpRequest.java @@ -217,8 +217,8 @@ public class NioHttpRequest implements HttpRequest { } @Override - public NioHttpResponse createResponse(RestStatus status, BytesReference content) { - return new NioHttpResponse(request.headers(), request.protocolVersion(), status, content); + public NioHttpResponse createResponse(RestStatus status, BytesReference contentRef) { + return new NioHttpResponse(request.headers(), request.protocolVersion(), status, contentRef); } @Override diff --git a/plugins/transport-nio/src/test/java/org/elasticsearch/http/nio/HttpReadWriteHandlerTests.java b/plugins/transport-nio/src/test/java/org/elasticsearch/http/nio/HttpReadWriteHandlerTests.java index 67ed75f631e9..47f43176169d 100644 --- a/plugins/transport-nio/src/test/java/org/elasticsearch/http/nio/HttpReadWriteHandlerTests.java +++ b/plugins/transport-nio/src/test/java/org/elasticsearch/http/nio/HttpReadWriteHandlerTests.java @@ -196,10 +196,10 @@ public class HttpReadWriteHandlerTests extends ESTestCase { HttpHandlingSettings httpHandlingSettings = HttpHandlingSettings.fromSettings(settings); CorsHandler corsHandler = CorsHandler.disabled(); - TaskScheduler taskScheduler = new TaskScheduler(); + TaskScheduler realScheduler = new TaskScheduler(); Iterator timeValues = Arrays.asList(0, 2, 4, 6, 8).iterator(); - handler = new HttpReadWriteHandler(channel, transport, httpHandlingSettings, taskScheduler, timeValues::next); + handler = new HttpReadWriteHandler(channel, transport, httpHandlingSettings, realScheduler, timeValues::next); handler.channelActive(); prepareHandlerForResponse(handler); @@ -207,31 +207,31 @@ public class HttpReadWriteHandlerTests extends ESTestCase { HttpWriteOperation writeOperation0 = new HttpWriteOperation(context, emptyGetResponse(0), mock(BiConsumer.class)); ((ChannelPromise) handler.writeToBytes(writeOperation0).get(0).getListener()).setSuccess(); - taskScheduler.pollTask(timeValue.getNanos() + 1).run(); + realScheduler.pollTask(timeValue.getNanos() + 1).run(); // There was a read. Do not close. verify(transport, times(0)).onException(eq(channel), any(HttpReadTimeoutException.class)); prepareHandlerForResponse(handler); prepareHandlerForResponse(handler); - taskScheduler.pollTask(timeValue.getNanos() + 3).run(); + realScheduler.pollTask(timeValue.getNanos() + 3).run(); // There was a read. Do not close. verify(transport, times(0)).onException(eq(channel), any(HttpReadTimeoutException.class)); HttpWriteOperation writeOperation1 = new HttpWriteOperation(context, emptyGetResponse(1), mock(BiConsumer.class)); ((ChannelPromise) handler.writeToBytes(writeOperation1).get(0).getListener()).setSuccess(); - taskScheduler.pollTask(timeValue.getNanos() + 5).run(); + realScheduler.pollTask(timeValue.getNanos() + 5).run(); // There has not been a read, however there is still an inflight request. Do not close. verify(transport, times(0)).onException(eq(channel), any(HttpReadTimeoutException.class)); HttpWriteOperation writeOperation2 = new HttpWriteOperation(context, emptyGetResponse(2), mock(BiConsumer.class)); ((ChannelPromise) handler.writeToBytes(writeOperation2).get(0).getListener()).setSuccess(); - taskScheduler.pollTask(timeValue.getNanos() + 7).run(); + realScheduler.pollTask(timeValue.getNanos() + 7).run(); // No reads and no inflight requests, close verify(transport, times(1)).onException(eq(channel), any(HttpReadTimeoutException.class)); - assertNull(taskScheduler.pollTask(timeValue.getNanos() + 9)); + assertNull(realScheduler.pollTask(timeValue.getNanos() + 9)); } private static HttpPipelinedResponse emptyGetResponse(int sequence) { @@ -242,7 +242,7 @@ public class HttpReadWriteHandlerTests extends ESTestCase { return httpResponse; } - private void prepareHandlerForResponse(HttpReadWriteHandler handler) throws IOException { + private void prepareHandlerForResponse(HttpReadWriteHandler readWriteHandler) throws IOException { HttpMethod method = randomBoolean() ? HttpMethod.GET : HttpMethod.HEAD; HttpVersion version = randomBoolean() ? HttpVersion.HTTP_1_0 : HttpVersion.HTTP_1_1; String uri = "http://localhost:9090/" + randomAlphaOfLength(8); @@ -250,7 +250,7 @@ public class HttpReadWriteHandlerTests extends ESTestCase { io.netty.handler.codec.http.HttpRequest request = new DefaultFullHttpRequest(version, method, uri); ByteBuf buf = requestEncoder.encode(request); try { - handler.consumeReads(toChannelBuffer(buf)); + readWriteHandler.consumeReads(toChannelBuffer(buf)); } finally { buf.release(); }