diff --git a/build-tools-internal/src/main/resources/checkstyle.xml b/build-tools-internal/src/main/resources/checkstyle.xml index fa3fe067480d9..abaab3a1a8ae0 100644 --- a/build-tools-internal/src/main/resources/checkstyle.xml +++ b/build-tools-internal/src/main/resources/checkstyle.xml @@ -114,6 +114,7 @@ + --> diff --git a/libs/nio/src/test/java/org/elasticsearch/nio/EventHandlerTests.java b/libs/nio/src/test/java/org/elasticsearch/nio/EventHandlerTests.java index 857fab8017925..82f211a3eb3be 100644 --- a/libs/nio/src/test/java/org/elasticsearch/nio/EventHandlerTests.java +++ b/libs/nio/src/test/java/org/elasticsearch/nio/EventHandlerTests.java @@ -83,18 +83,18 @@ public void testRegisterCallsContext() throws IOException { } public void testActiveNonServerAddsOP_CONNECTAndOP_READInterest() throws IOException { - SocketChannelContext context = mock(SocketChannelContext.class); - when(context.getSelectionKey()).thenReturn(new TestSelectionKey(0)); - handler.handleActive(context); - assertEquals(SelectionKey.OP_READ | SelectionKey.OP_CONNECT, context.getSelectionKey().interestOps()); + SocketChannelContext mockContext = mock(SocketChannelContext.class); + when(mockContext.getSelectionKey()).thenReturn(new TestSelectionKey(0)); + handler.handleActive(mockContext); + assertEquals(SelectionKey.OP_READ | SelectionKey.OP_CONNECT, mockContext.getSelectionKey().interestOps()); } public void testHandleServerActiveSetsOP_ACCEPTInterest() throws IOException { - ServerChannelContext serverContext = mock(ServerChannelContext.class); - when(serverContext.getSelectionKey()).thenReturn(new TestSelectionKey(0)); - handler.handleActive(serverContext); + ServerChannelContext mockServerContext = mock(ServerChannelContext.class); + when(mockServerContext.getSelectionKey()).thenReturn(new TestSelectionKey(0)); + handler.handleActive(mockServerContext); - assertEquals(SelectionKey.OP_ACCEPT, serverContext.getSelectionKey().interestOps()); + assertEquals(SelectionKey.OP_ACCEPT, mockServerContext.getSelectionKey().interestOps()); } public void testHandleAcceptAccept() throws IOException { @@ -146,9 +146,9 @@ public void testConnectExceptionCallsExceptionHandler() throws IOException { } public void testHandleReadDelegatesToContext() throws IOException { - SocketChannelContext context = mock(SocketChannelContext.class); - handler.handleRead(context); - verify(context).read(); + SocketChannelContext mockContext = mock(SocketChannelContext.class); + handler.handleRead(mockContext); + verify(mockContext).read(); } public void testReadExceptionCallsExceptionHandler() { @@ -165,53 +165,53 @@ public void testWriteExceptionCallsExceptionHandler() { public void testPostHandlingCallWillCloseTheChannelIfReady() throws IOException { NioSocketChannel channel = mock(NioSocketChannel.class); - SocketChannelContext context = mock(SocketChannelContext.class); + SocketChannelContext mockContext = mock(SocketChannelContext.class); - when(channel.getContext()).thenReturn(context); - when(context.selectorShouldClose()).thenReturn(true); - handler.postHandling(context); + when(channel.getContext()).thenReturn(mockContext); + when(mockContext.selectorShouldClose()).thenReturn(true); + handler.postHandling(mockContext); - verify(context).closeFromSelector(); + verify(mockContext).closeFromSelector(); } public void testPostHandlingCallWillNotCloseTheChannelIfNotReady() throws IOException { - SocketChannelContext context = mock(SocketChannelContext.class); - when(context.getSelectionKey()).thenReturn(new TestSelectionKey(SelectionKey.OP_READ | SelectionKey.OP_WRITE)); - when(context.selectorShouldClose()).thenReturn(false); + SocketChannelContext mockContext = mock(SocketChannelContext.class); + when(mockContext.getSelectionKey()).thenReturn(new TestSelectionKey(SelectionKey.OP_READ | SelectionKey.OP_WRITE)); + when(mockContext.selectorShouldClose()).thenReturn(false); NioSocketChannel channel = mock(NioSocketChannel.class); - when(channel.getContext()).thenReturn(context); + when(channel.getContext()).thenReturn(mockContext); - handler.postHandling(context); + handler.postHandling(mockContext); - verify(context, times(0)).closeFromSelector(); + verify(mockContext, times(0)).closeFromSelector(); } public void testPostHandlingWillAddWriteIfNecessary() throws IOException { TestSelectionKey selectionKey = new TestSelectionKey(SelectionKey.OP_READ); - SocketChannelContext context = mock(SocketChannelContext.class); - when(context.getSelectionKey()).thenReturn(selectionKey); - when(context.readyForFlush()).thenReturn(true); + SocketChannelContext mockContext = mock(SocketChannelContext.class); + when(mockContext.getSelectionKey()).thenReturn(selectionKey); + when(mockContext.readyForFlush()).thenReturn(true); NioSocketChannel channel = mock(NioSocketChannel.class); - when(channel.getContext()).thenReturn(context); + when(channel.getContext()).thenReturn(mockContext); assertEquals(SelectionKey.OP_READ, selectionKey.interestOps()); - handler.postHandling(context); + handler.postHandling(mockContext); assertEquals(SelectionKey.OP_READ | SelectionKey.OP_WRITE, selectionKey.interestOps()); } public void testPostHandlingWillRemoveWriteIfNecessary() throws IOException { TestSelectionKey key = new TestSelectionKey(SelectionKey.OP_READ | SelectionKey.OP_WRITE); - SocketChannelContext context = mock(SocketChannelContext.class); - when(context.getSelectionKey()).thenReturn(key); - when(context.readyForFlush()).thenReturn(false); + SocketChannelContext mockContext = mock(SocketChannelContext.class); + when(mockContext.getSelectionKey()).thenReturn(key); + when(mockContext.readyForFlush()).thenReturn(false); NioSocketChannel channel = mock(NioSocketChannel.class); - when(channel.getContext()).thenReturn(context); + when(channel.getContext()).thenReturn(mockContext); assertEquals(SelectionKey.OP_READ | SelectionKey.OP_WRITE, key.interestOps()); - handler.postHandling(context); + handler.postHandling(mockContext); assertEquals(SelectionKey.OP_READ, key.interestOps()); } diff --git a/libs/nio/src/test/java/org/elasticsearch/nio/NioSelectorTests.java b/libs/nio/src/test/java/org/elasticsearch/nio/NioSelectorTests.java index 030bb5f3bad72..5fbe122415398 100644 --- a/libs/nio/src/test/java/org/elasticsearch/nio/NioSelectorTests.java +++ b/libs/nio/src/test/java/org/elasticsearch/nio/NioSelectorTests.java @@ -85,12 +85,12 @@ public void setUp() throws Exception { @SuppressWarnings({ "unchecked", "rawtypes" }) public void testQueueChannelForClosed() throws IOException { - NioChannel channel = mock(NioChannel.class); + NioChannel mockChannel = mock(NioChannel.class); ChannelContext context = mock(ChannelContext.class); - when(channel.getContext()).thenReturn(context); + when(mockChannel.getContext()).thenReturn(context); when(context.getSelector()).thenReturn(selector); - selector.queueChannelClose(channel); + selector.queueChannelClose(mockChannel); selector.singleLoop(); @@ -100,12 +100,12 @@ public void testQueueChannelForClosed() throws IOException { @SuppressWarnings({ "unchecked", "rawtypes" }) public void testCloseException() throws IOException, InterruptedException { IOException ioException = new IOException(); - NioChannel channel = mock(NioChannel.class); + NioChannel mockChannel = mock(NioChannel.class); ChannelContext context = mock(ChannelContext.class); - when(channel.getContext()).thenReturn(context); + when(mockChannel.getContext()).thenReturn(context); when(context.getSelector()).thenReturn(selector); - executeOnNewThread(() -> selector.queueChannelClose(channel)); + executeOnNewThread(() -> selector.queueChannelClose(mockChannel)); doThrow(ioException).when(eventHandler).handleClose(context); diff --git a/libs/nio/src/test/java/org/elasticsearch/nio/SocketChannelContextTests.java b/libs/nio/src/test/java/org/elasticsearch/nio/SocketChannelContextTests.java index a9f845073bf4f..1c2f9f6adfd57 100644 --- a/libs/nio/src/test/java/org/elasticsearch/nio/SocketChannelContextTests.java +++ b/libs/nio/src/test/java/org/elasticsearch/nio/SocketChannelContextTests.java @@ -126,8 +126,8 @@ public void testRegisterInitiatesConnect() throws IOException { isAccepted ); InboundChannelBuffer buffer = InboundChannelBuffer.allocatingInstance(); - TestSocketChannelContext context = new TestSocketChannelContext(channel, selector, exceptionHandler, handler, buffer, config); - context.register(); + TestSocketChannelContext testContext = new TestSocketChannelContext(channel, selector, exceptionHandler, handler, buffer, config); + testContext.register(); if (isAccepted) { verify(rawChannel, times(0)).connect(any(InetSocketAddress.class)); } else { @@ -205,11 +205,11 @@ public void testConnectCanSetSocketOptions() throws IOException { false ); InboundChannelBuffer buffer = InboundChannelBuffer.allocatingInstance(); - TestSocketChannelContext context = new TestSocketChannelContext(channel, selector, exceptionHandler, handler, buffer, config); + TestSocketChannelContext testContext = new TestSocketChannelContext(channel, selector, exceptionHandler, handler, buffer, config); doThrow(new SocketException()).doNothing().when(rawSocket).setReuseAddress(tcpReuseAddress); - context.register(); + testContext.register(); when(rawChannel.finishConnect()).thenReturn(true); - context.connect(); + testContext.connect(); verify(rawSocket, times(2)).setReuseAddress(tcpReuseAddress); verify(rawSocket).setKeepAlive(tcpKeepAlive); @@ -339,7 +339,7 @@ public void testCloseClosesWriteProducer() throws IOException { when(channel.getRawChannel()).thenReturn(realChannel); when(channel.isOpen()).thenReturn(true); InboundChannelBuffer buffer = InboundChannelBuffer.allocatingInstance(); - BytesChannelContext context = new BytesChannelContext( + BytesChannelContext bytesChannelContext = new BytesChannelContext( channel, selector, mock(Config.Socket.class), @@ -347,7 +347,7 @@ public void testCloseClosesWriteProducer() throws IOException { handler, buffer ); - context.closeFromSelector(); + bytesChannelContext.closeFromSelector(); verify(handler).close(); } } @@ -360,8 +360,8 @@ public void testCloseClosesChannelBuffer() throws IOException { IntFunction pageAllocator = (n) -> new Page(ByteBuffer.allocate(n), closer); InboundChannelBuffer buffer = new InboundChannelBuffer(pageAllocator); buffer.ensureCapacity(1); - TestSocketChannelContext context = new TestSocketChannelContext(channel, selector, exceptionHandler, handler, buffer); - context.closeFromSelector(); + TestSocketChannelContext testContext = new TestSocketChannelContext(channel, selector, exceptionHandler, handler, buffer); + testContext.closeFromSelector(); verify(closer).close(); } } diff --git a/libs/nio/src/test/java/org/elasticsearch/nio/TestSelectionKey.java b/libs/nio/src/test/java/org/elasticsearch/nio/TestSelectionKey.java index 91ee754eef886..b0da6af7d730a 100644 --- a/libs/nio/src/test/java/org/elasticsearch/nio/TestSelectionKey.java +++ b/libs/nio/src/test/java/org/elasticsearch/nio/TestSelectionKey.java @@ -15,11 +15,11 @@ public class TestSelectionKey extends AbstractSelectionKey { - private int ops = 0; + private int interestOps = 0; private int readyOps; public TestSelectionKey(int ops) { - this.ops = ops; + this.interestOps = ops; } @Override @@ -34,12 +34,12 @@ public Selector selector() { @Override public int interestOps() { - return ops; + return interestOps; } @Override public SelectionKey interestOps(int ops) { - this.ops = ops; + this.interestOps = ops; return this; } diff --git a/libs/x-content/src/main/java/org/elasticsearch/xcontent/XContentParserConfiguration.java b/libs/x-content/src/main/java/org/elasticsearch/xcontent/XContentParserConfiguration.java index b2e3ea504350a..21765a7e3a54d 100644 --- a/libs/x-content/src/main/java/org/elasticsearch/xcontent/XContentParserConfiguration.java +++ b/libs/x-content/src/main/java/org/elasticsearch/xcontent/XContentParserConfiguration.java @@ -93,13 +93,13 @@ public RestApiVersion restApiVersion() { /** * Replace the configured filtering. */ - public XContentParserConfiguration withFiltering(Set includes, Set excludes) { + public XContentParserConfiguration withFiltering(Set includeStrings, Set excludeStrings) { return new XContentParserConfiguration( registry, deprecationHandler, restApiVersion, - FilterPath.compile(includes), - FilterPath.compile(excludes) + FilterPath.compile(includeStrings), + FilterPath.compile(excludeStrings) ); } diff --git a/libs/x-content/src/test/java/org/elasticsearch/xcontent/ConstructingObjectParserTests.java b/libs/x-content/src/test/java/org/elasticsearch/xcontent/ConstructingObjectParserTests.java index ce83b11007896..3fc353ad0f103 100644 --- a/libs/x-content/src/test/java/org/elasticsearch/xcontent/ConstructingObjectParserTests.java +++ b/libs/x-content/src/test/java/org/elasticsearch/xcontent/ConstructingObjectParserTests.java @@ -380,7 +380,7 @@ public XContentBuilder toXContent(XContentBuilder builder, Params params) throws private static ConstructingObjectParser buildParser(boolean animalRequired, boolean vegetableRequired) { ConstructingObjectParser parser = new ConstructingObjectParser<>( "has_required_arguments", - a -> new HasCtorArguments((String) a[0], (Integer) a[1]) + args -> new HasCtorArguments((String) args[0], (Integer) args[1]) ); parser.declareString(animalRequired ? constructorArg() : optionalConstructorArg(), new ParseField("animal")); parser.declareInt(vegetableRequired ? constructorArg() : optionalConstructorArg(), new ParseField("vegetable")); diff --git a/libs/x-content/src/test/java/org/elasticsearch/xcontent/ObjectParserTests.java b/libs/x-content/src/test/java/org/elasticsearch/xcontent/ObjectParserTests.java index 9d5f6e1450500..3bfb29bc2a269 100644 --- a/libs/x-content/src/test/java/org/elasticsearch/xcontent/ObjectParserTests.java +++ b/libs/x-content/src/test/java/org/elasticsearch/xcontent/ObjectParserTests.java @@ -167,7 +167,7 @@ public void setName(String name) { this.name = name; } - public void setURI(URI uri) { + public void setUri(URI uri) { this.uri = uri; } } @@ -180,9 +180,9 @@ class CustomParseContext { this.parser = parser; } - public URI parseURI(XContentParser parser) { + public URI parseURI(XContentParser xContentParser) { try { - return this.parser.parseURI(parser); + return this.parser.parseURI(xContentParser); } catch (IOException e) { throw new UncheckedIOException(e); } @@ -194,7 +194,7 @@ public URI parseURI(XContentParser parser) { ); ObjectParser objectParser = new ObjectParser<>("foo"); objectParser.declareString(Foo::setName, new ParseField("name")); - objectParser.declareObjectOrDefault(Foo::setURI, (p, s) -> s.parseURI(p), () -> null, new ParseField("url")); + objectParser.declareObjectOrDefault(Foo::setUri, (p, s) -> s.parseURI(p), () -> null, new ParseField("url")); Foo s = objectParser.parse(parser, new Foo(), new CustomParseContext(new ClassicParser())); assertEquals(s.uri.getHost(), "foobar"); assertEquals(s.uri.getPort(), 80); @@ -705,8 +705,8 @@ public void setInts(List ints) { this.ints = ints; } - public void setArray(List testArray) { - this.testArray = testArray; + public void setArray(List array) { + this.testArray = array; } } ObjectParser objectParser = new ObjectParser<>("foo"); diff --git a/modules/aggs-matrix-stats/src/main/java/org/elasticsearch/search/aggregations/matrix/ArrayValuesSourceAggregationBuilder.java b/modules/aggs-matrix-stats/src/main/java/org/elasticsearch/search/aggregations/matrix/ArrayValuesSourceAggregationBuilder.java index 86a1151333e59..1d945d1265fb9 100644 --- a/modules/aggs-matrix-stats/src/main/java/org/elasticsearch/search/aggregations/matrix/ArrayValuesSourceAggregationBuilder.java +++ b/modules/aggs-matrix-stats/src/main/java/org/elasticsearch/search/aggregations/matrix/ArrayValuesSourceAggregationBuilder.java @@ -130,11 +130,11 @@ protected final void doWriteTo(StreamOutput out) throws IOException { * Sets the field to use for this aggregation. */ @SuppressWarnings("unchecked") - public AB fields(List fields) { - if (fields == null) { + public AB fields(List fieldsArg) { + if (fieldsArg == null) { throw new IllegalArgumentException("[field] must not be null: [" + name + "]"); } - this.fields = fields; + this.fields = fieldsArg; return (AB) this; } @@ -149,11 +149,11 @@ public List fields() { * Sets the format to use for the output of the aggregation. */ @SuppressWarnings("unchecked") - public AB format(String format) { - if (format == null) { + public AB format(String formatArg) { + if (formatArg == null) { throw new IllegalArgumentException("[format] must not be null: [" + name + "]"); } - this.format = format; + this.format = formatArg; return (AB) this; } @@ -169,11 +169,11 @@ public String format() { * document */ @SuppressWarnings("unchecked") - public AB missingMap(Map missingMap) { - if (missingMap == null) { + public AB missingMap(Map missingMapArg) { + if (missingMapArg == null) { throw new IllegalArgumentException("[missing] must not be null: [" + name + "]"); } - this.missingMap = missingMap; + this.missingMap = missingMapArg; return (AB) this; } diff --git a/modules/aggs-matrix-stats/src/main/java/org/elasticsearch/search/aggregations/matrix/stats/InternalMatrixStats.java b/modules/aggs-matrix-stats/src/main/java/org/elasticsearch/search/aggregations/matrix/stats/InternalMatrixStats.java index 78df56972c31d..2a3f9768429e6 100644 --- a/modules/aggs-matrix-stats/src/main/java/org/elasticsearch/search/aggregations/matrix/stats/InternalMatrixStats.java +++ b/modules/aggs-matrix-stats/src/main/java/org/elasticsearch/search/aggregations/matrix/stats/InternalMatrixStats.java @@ -242,8 +242,8 @@ public InternalAggregation reduce(List aggregations, Reduce } if (reduceContext.isFinalReduce()) { - MatrixStatsResults results = new MatrixStatsResults(runningStats); - return new InternalMatrixStats(name, results.getDocCount(), runningStats, results, getMetadata()); + MatrixStatsResults matrixStatsResults = new MatrixStatsResults(runningStats); + return new InternalMatrixStats(name, matrixStatsResults.getDocCount(), runningStats, matrixStatsResults, getMetadata()); } return new InternalMatrixStats(name, runningStats.docCount, runningStats, null, getMetadata()); } diff --git a/modules/aggs-matrix-stats/src/test/java/org/elasticsearch/search/aggregations/matrix/stats/InternalMatrixStatsTests.java b/modules/aggs-matrix-stats/src/test/java/org/elasticsearch/search/aggregations/matrix/stats/InternalMatrixStatsTests.java index 5d4701155ab18..75a96dd8b5e7c 100644 --- a/modules/aggs-matrix-stats/src/test/java/org/elasticsearch/search/aggregations/matrix/stats/InternalMatrixStatsTests.java +++ b/modules/aggs-matrix-stats/src/test/java/org/elasticsearch/search/aggregations/matrix/stats/InternalMatrixStatsTests.java @@ -89,14 +89,14 @@ protected InternalMatrixStats mutateInstance(InternalMatrixStats instance) { name += randomAlphaOfLength(5); break; case 1: - String[] fields = Arrays.copyOf(this.fields, this.fields.length + 1); - fields[fields.length - 1] = "field_" + (fields.length - 1); - double[] values = new double[fields.length]; - for (int i = 0; i < fields.length; i++) { + String[] fieldsCopy = Arrays.copyOf(this.fields, this.fields.length + 1); + fieldsCopy[fieldsCopy.length - 1] = "field_" + (fieldsCopy.length - 1); + double[] values = new double[fieldsCopy.length]; + for (int i = 0; i < fieldsCopy.length; i++) { values[i] = randomDouble() * 200; } runningStats = new RunningStats(); - runningStats.add(fields, values); + runningStats.add(fieldsCopy, values); break; case 2: if (matrixStatsResults == null) { diff --git a/modules/analysis-common/src/main/java/org/elasticsearch/analysis/common/CJKBigramFilterFactory.java b/modules/analysis-common/src/main/java/org/elasticsearch/analysis/common/CJKBigramFilterFactory.java index 09e0767c054ef..c7b47f4aa7892 100644 --- a/modules/analysis-common/src/main/java/org/elasticsearch/analysis/common/CJKBigramFilterFactory.java +++ b/modules/analysis-common/src/main/java/org/elasticsearch/analysis/common/CJKBigramFilterFactory.java @@ -41,6 +41,7 @@ public final class CJKBigramFilterFactory extends AbstractTokenFilterFactory { private final int flags; private final boolean outputUnigrams; + @SuppressWarnings("HiddenField") CJKBigramFilterFactory(IndexSettings indexSettings, Environment environment, String name, Settings settings) { super(indexSettings, name, settings); outputUnigrams = settings.getAsBoolean("output_unigrams", false); diff --git a/modules/analysis-common/src/main/java/org/elasticsearch/analysis/common/CommonAnalysisPlugin.java b/modules/analysis-common/src/main/java/org/elasticsearch/analysis/common/CommonAnalysisPlugin.java index 9a598478a8ffe..694cd1f5ab141 100644 --- a/modules/analysis-common/src/main/java/org/elasticsearch/analysis/common/CommonAnalysisPlugin.java +++ b/modules/analysis-common/src/main/java/org/elasticsearch/analysis/common/CommonAnalysisPlugin.java @@ -148,7 +148,7 @@ public class CommonAnalysisPlugin extends Plugin implements AnalysisPlugin, Scri private static final DeprecationLogger deprecationLogger = DeprecationLogger.getLogger(CommonAnalysisPlugin.class); - private final SetOnce scriptService = new SetOnce<>(); + private final SetOnce scriptServiceHolder = new SetOnce<>(); @Override public Collection createComponents( @@ -164,7 +164,7 @@ public Collection createComponents( IndexNameExpressionResolver expressionResolver, Supplier repositoriesServiceSupplier ) { - this.scriptService.set(scriptService); + this.scriptServiceHolder.set(scriptService); return Collections.emptyList(); } @@ -236,7 +236,7 @@ public Map> getTokenFilters() { filters.put("common_grams", requiresAnalysisSettings(CommonGramsTokenFilterFactory::new)); filters.put( "condition", - requiresAnalysisSettings((i, e, n, s) -> new ScriptedConditionTokenFilterFactory(i, n, s, scriptService.get())) + requiresAnalysisSettings((i, e, n, s) -> new ScriptedConditionTokenFilterFactory(i, n, s, scriptServiceHolder.get())) ); filters.put("decimal_digit", DecimalDigitFilterFactory::new); filters.put("delimited_payload", DelimitedPayloadTokenFilterFactory::new); @@ -312,7 +312,7 @@ public TokenStream create(TokenStream tokenStream) { filters.put("porter_stem", PorterStemTokenFilterFactory::new); filters.put( "predicate_token_filter", - requiresAnalysisSettings((i, e, n, s) -> new PredicateTokenFilterScriptFactory(i, n, s, scriptService.get())) + requiresAnalysisSettings((i, e, n, s) -> new PredicateTokenFilterScriptFactory(i, n, s, scriptServiceHolder.get())) ); filters.put("remove_duplicates", RemoveDuplicatesTokenFilterFactory::new); filters.put("reverse", ReverseTokenFilterFactory::new); diff --git a/modules/analysis-common/src/main/java/org/elasticsearch/analysis/common/HtmlStripCharFilterFactory.java b/modules/analysis-common/src/main/java/org/elasticsearch/analysis/common/HtmlStripCharFilterFactory.java index 37e289847ed68..7f1d232f0f1ba 100644 --- a/modules/analysis-common/src/main/java/org/elasticsearch/analysis/common/HtmlStripCharFilterFactory.java +++ b/modules/analysis-common/src/main/java/org/elasticsearch/analysis/common/HtmlStripCharFilterFactory.java @@ -26,9 +26,9 @@ public class HtmlStripCharFilterFactory extends AbstractCharFilterFactory { HtmlStripCharFilterFactory(IndexSettings indexSettings, Environment env, String name, Settings settings) { super(indexSettings, name); - List escapedTags = settings.getAsList("escaped_tags"); - if (escapedTags.size() > 0) { - this.escapedTags = unmodifiableSet(newHashSet(escapedTags)); + List escapedTagsList = settings.getAsList("escaped_tags"); + if (escapedTagsList.size() > 0) { + this.escapedTags = unmodifiableSet(newHashSet(escapedTagsList)); } else { this.escapedTags = null; } diff --git a/modules/analysis-common/src/main/java/org/elasticsearch/analysis/common/MultiplexerTokenFilterFactory.java b/modules/analysis-common/src/main/java/org/elasticsearch/analysis/common/MultiplexerTokenFilterFactory.java index 9bd239b444805..0bc18ae794d27 100644 --- a/modules/analysis-common/src/main/java/org/elasticsearch/analysis/common/MultiplexerTokenFilterFactory.java +++ b/modules/analysis-common/src/main/java/org/elasticsearch/analysis/common/MultiplexerTokenFilterFactory.java @@ -149,17 +149,17 @@ private final class MultiplexTokenFilter extends TokenFilter { */ MultiplexTokenFilter(TokenStream input, List> filters) { super(input); - TokenStream source = new MultiplexerFilter(input); + TokenStream sourceFilter = new MultiplexerFilter(input); for (int i = 0; i < filters.size(); i++) { final int slot = i; - source = new ConditionalTokenFilter(source, filters.get(i)) { + sourceFilter = new ConditionalTokenFilter(sourceFilter, filters.get(i)) { @Override protected boolean shouldFilter() { return slot == selector; } }; } - this.source = source; + this.source = sourceFilter; this.filterCount = filters.size(); this.selector = filterCount - 1; } diff --git a/modules/analysis-common/src/main/java/org/elasticsearch/analysis/common/PathHierarchyTokenizerFactory.java b/modules/analysis-common/src/main/java/org/elasticsearch/analysis/common/PathHierarchyTokenizerFactory.java index 3dc86fc40ae04..969ef2fd86e8f 100644 --- a/modules/analysis-common/src/main/java/org/elasticsearch/analysis/common/PathHierarchyTokenizerFactory.java +++ b/modules/analysis-common/src/main/java/org/elasticsearch/analysis/common/PathHierarchyTokenizerFactory.java @@ -28,22 +28,22 @@ public class PathHierarchyTokenizerFactory extends AbstractTokenizerFactory { PathHierarchyTokenizerFactory(IndexSettings indexSettings, Environment environment, String name, Settings settings) { super(indexSettings, settings, name); bufferSize = settings.getAsInt("buffer_size", 1024); - String delimiter = settings.get("delimiter"); - if (delimiter == null) { + String delimiterString = settings.get("delimiter"); + if (delimiterString == null) { this.delimiter = PathHierarchyTokenizer.DEFAULT_DELIMITER; - } else if (delimiter.length() != 1) { + } else if (delimiterString.length() != 1) { throw new IllegalArgumentException("delimiter must be a one char value"); } else { - this.delimiter = delimiter.charAt(0); + this.delimiter = delimiterString.charAt(0); } - String replacement = settings.get("replacement"); - if (replacement == null) { + String replacementString = settings.get("replacement"); + if (replacementString == null) { this.replacement = this.delimiter; - } else if (replacement.length() != 1) { + } else if (replacementString.length() != 1) { throw new IllegalArgumentException("replacement must be a one char value"); } else { - this.replacement = replacement.charAt(0); + this.replacement = replacementString.charAt(0); } this.skip = settings.getAsInt("skip", PathHierarchyTokenizer.DEFAULT_SKIP); this.reverse = settings.getAsBoolean("reverse", false); diff --git a/modules/analysis-common/src/main/java/org/elasticsearch/analysis/common/WordDelimiterGraphTokenFilterFactory.java b/modules/analysis-common/src/main/java/org/elasticsearch/analysis/common/WordDelimiterGraphTokenFilterFactory.java index 58fb80021c663..7271dee894991 100644 --- a/modules/analysis-common/src/main/java/org/elasticsearch/analysis/common/WordDelimiterGraphTokenFilterFactory.java +++ b/modules/analysis-common/src/main/java/org/elasticsearch/analysis/common/WordDelimiterGraphTokenFilterFactory.java @@ -41,6 +41,7 @@ public class WordDelimiterGraphTokenFilterFactory extends AbstractTokenFilterFac private final CharArraySet protoWords; private final boolean adjustOffsets; + @SuppressWarnings("HiddenField") public WordDelimiterGraphTokenFilterFactory(IndexSettings indexSettings, Environment env, String name, Settings settings) { super(indexSettings, name, settings); diff --git a/modules/analysis-common/src/main/java/org/elasticsearch/analysis/common/WordDelimiterTokenFilterFactory.java b/modules/analysis-common/src/main/java/org/elasticsearch/analysis/common/WordDelimiterTokenFilterFactory.java index f4d1ed1e2ea8f..7703a66f2cef4 100644 --- a/modules/analysis-common/src/main/java/org/elasticsearch/analysis/common/WordDelimiterTokenFilterFactory.java +++ b/modules/analysis-common/src/main/java/org/elasticsearch/analysis/common/WordDelimiterTokenFilterFactory.java @@ -44,6 +44,7 @@ public class WordDelimiterTokenFilterFactory extends AbstractTokenFilterFactory private final int flags; private final CharArraySet protoWords; + @SuppressWarnings("HiddenField") public WordDelimiterTokenFilterFactory(IndexSettings indexSettings, Environment env, String name, Settings settings) { super(indexSettings, name, settings); diff --git a/modules/ingest-common/src/main/java/org/elasticsearch/ingest/common/CsvParser.java b/modules/ingest-common/src/main/java/org/elasticsearch/ingest/common/CsvParser.java index 6739ce5a41b4e..a87bac2f65549 100644 --- a/modules/ingest-common/src/main/java/org/elasticsearch/ingest/common/CsvParser.java +++ b/modules/ingest-common/src/main/java/org/elasticsearch/ingest/common/CsvParser.java @@ -47,9 +47,9 @@ private enum State { this.emptyValue = emptyValue; } - void process(String line) { - this.line = line; - length = line.length(); + void process(String lineValue) { + this.line = lineValue; + length = lineValue.length(); for (currentIndex = 0; currentIndex < length; currentIndex++) { switch (state) { case START: diff --git a/modules/ingest-common/src/main/java/org/elasticsearch/ingest/common/DotExpanderProcessor.java b/modules/ingest-common/src/main/java/org/elasticsearch/ingest/common/DotExpanderProcessor.java index cf660683096d7..5174ea614c0ee 100644 --- a/modules/ingest-common/src/main/java/org/elasticsearch/ingest/common/DotExpanderProcessor.java +++ b/modules/ingest-common/src/main/java/org/elasticsearch/ingest/common/DotExpanderProcessor.java @@ -38,59 +38,63 @@ public final class DotExpanderProcessor extends AbstractProcessor { @Override @SuppressWarnings("unchecked") public IngestDocument execute(IngestDocument ingestDocument) throws Exception { - String path; + String pathToExpand; Map map; if (this.path != null) { - path = this.path + "." + field; + pathToExpand = this.path + "." + field; map = ingestDocument.getFieldValue(this.path, Map.class); } else { - path = field; + pathToExpand = field; map = ingestDocument.getSourceAndMetadata(); } if (this.field.equals("*")) { for (String key : new ArrayList<>(map.keySet())) { if (key.indexOf('.') > 0) { - path = this.path != null ? this.path + "." + key : key; - expandDot(ingestDocument, path, key, map); + pathToExpand = this.path != null ? this.path + "." + key : key; + expandDot(ingestDocument, pathToExpand, key, map); } } } else { - expandDot(ingestDocument, path, field, map); + expandDot(ingestDocument, pathToExpand, field, map); } return ingestDocument; } - private void expandDot(IngestDocument ingestDocument, String path, String field, Map map) { - if (map.containsKey(field)) { - if (ingestDocument.hasField(path)) { - Object value = map.remove(field); + private void expandDot(IngestDocument ingestDocument, String pathToExpand, String fieldName, Map map) { + if (map.containsKey(fieldName)) { + if (ingestDocument.hasField(pathToExpand)) { + Object value = map.remove(fieldName); if (override) { - ingestDocument.setFieldValue(path, value); + ingestDocument.setFieldValue(pathToExpand, value); } else { - ingestDocument.appendFieldValue(path, value); + ingestDocument.appendFieldValue(pathToExpand, value); } } else { // check whether we actually can expand the field in question into an object field. // part of the path may already exist and if part of it would be a value field (string, integer etc.) // then we can't override it with an object field and we should fail with a good reason. // IngestDocument#setFieldValue(...) would fail too, but the error isn't very understandable - for (int index = path.indexOf('.'); index != -1; index = path.indexOf('.', index + 1)) { - String partialPath = path.substring(0, index); + for (int index = pathToExpand.indexOf('.'); index != -1; index = pathToExpand.indexOf('.', index + 1)) { + String partialPath = pathToExpand.substring(0, index); if (ingestDocument.hasField(partialPath)) { Object val = ingestDocument.getFieldValue(partialPath, Object.class); if ((val instanceof Map) == false) { throw new IllegalArgumentException( - "cannot expend [" + path + "], because [" + partialPath + "] is not an object field, but a value field" + "cannot expand [" + + pathToExpand + + "], because [" + + partialPath + + "] is not an object field, but a value field" ); } } else { break; } } - Object value = map.remove(field); - ingestDocument.setFieldValue(path, value); + Object value = map.remove(fieldName); + ingestDocument.setFieldValue(pathToExpand, value); } } } diff --git a/modules/ingest-common/src/test/java/org/elasticsearch/ingest/common/DotExpanderProcessorTests.java b/modules/ingest-common/src/test/java/org/elasticsearch/ingest/common/DotExpanderProcessorTests.java index 4dfa92fb5598d..ccb685b2af14d 100644 --- a/modules/ingest-common/src/test/java/org/elasticsearch/ingest/common/DotExpanderProcessorTests.java +++ b/modules/ingest-common/src/test/java/org/elasticsearch/ingest/common/DotExpanderProcessorTests.java @@ -71,7 +71,7 @@ public void testEscapeFields_valueField() throws Exception { Processor processor1 = new DotExpanderProcessor("_tag", null, null, "foo.bar"); // foo already exists and if a leaf field and therefor can't be replaced by a map field: Exception e = expectThrows(IllegalArgumentException.class, () -> processor1.execute(document1)); - assertThat(e.getMessage(), equalTo("cannot expend [foo.bar], because [foo] is not an object field, but a value field")); + assertThat(e.getMessage(), equalTo("cannot expand [foo.bar], because [foo] is not an object field, but a value field")); // so because foo is no branch field but a value field the `foo.bar` field can't be expanded // into [foo].[bar], so foo should be renamed first into `[foo].[bar]: @@ -114,7 +114,7 @@ public void testEscapeFields_valueField() throws Exception { IngestDocument document2 = new IngestDocument(source, Collections.emptyMap()); Processor processor2 = new DotExpanderProcessor("_tag", null, null, "foo.bar.baz"); e = expectThrows(IllegalArgumentException.class, () -> processor2.execute(document2)); - assertThat(e.getMessage(), equalTo("cannot expend [foo.bar.baz], because [foo.bar] is not an object field, but a value field")); + assertThat(e.getMessage(), equalTo("cannot expand [foo.bar.baz], because [foo.bar] is not an object field, but a value field")); } public void testEscapeFields_path() throws Exception { diff --git a/modules/ingest-geoip/src/main/java/org/elasticsearch/ingest/geoip/ConfigDatabases.java b/modules/ingest-geoip/src/main/java/org/elasticsearch/ingest/geoip/ConfigDatabases.java index 9b490f7408d4f..bc6af4747b90b 100644 --- a/modules/ingest-geoip/src/main/java/org/elasticsearch/ingest/geoip/ConfigDatabases.java +++ b/modules/ingest-geoip/src/main/java/org/elasticsearch/ingest/geoip/ConfigDatabases.java @@ -53,7 +53,7 @@ final class ConfigDatabases implements Closeable { } void initialize(ResourceWatcherService resourceWatcher) throws IOException { - configDatabases.putAll(initConfigDatabases(geoipConfigDir)); + configDatabases.putAll(initConfigDatabases()); FileWatcher watcher = new FileWatcher(geoipConfigDir); watcher.addListener(new GeoipDirectoryListener()); @@ -91,7 +91,7 @@ void updateDatabase(Path file, boolean update) { } } - Map initConfigDatabases(Path geoipConfigDir) throws IOException { + Map initConfigDatabases() throws IOException { Map databases = new HashMap<>(); if (geoipConfigDir != null && Files.exists(geoipConfigDir)) { diff --git a/modules/ingest-geoip/src/main/java/org/elasticsearch/ingest/geoip/DatabaseNodeService.java b/modules/ingest-geoip/src/main/java/org/elasticsearch/ingest/geoip/DatabaseNodeService.java index 36240070f3a98..6313c8693835b 100644 --- a/modules/ingest-geoip/src/main/java/org/elasticsearch/ingest/geoip/DatabaseNodeService.java +++ b/modules/ingest-geoip/src/main/java/org/elasticsearch/ingest/geoip/DatabaseNodeService.java @@ -110,7 +110,7 @@ public final class DatabaseNodeService implements Closeable { this.genericExecutor = genericExecutor; } - public void initialize(String nodeId, ResourceWatcherService resourceWatcher, IngestService ingestService) throws IOException { + public void initialize(String nodeId, ResourceWatcherService resourceWatcher, IngestService ingestServiceArg) throws IOException { configDatabases.initialize(resourceWatcher); geoipTmpDirectory = geoipTmpBaseDirectory.resolve(nodeId); Files.walkFileTree(geoipTmpDirectory, new FileVisitor<>() { @@ -147,8 +147,8 @@ public FileVisitResult postVisitDirectory(Path dir, IOException exc) { Files.createDirectories(geoipTmpDirectory); } LOGGER.info("initialized database registry, using geoip-databases directory [{}]", geoipTmpDirectory); - ingestService.addIngestClusterStateListener(this::checkDatabases); - this.ingestService = ingestService; + ingestServiceArg.addIngestClusterStateListener(this::checkDatabases); + this.ingestService = ingestServiceArg; } public DatabaseReaderLazyLoader getDatabase(String name) { diff --git a/modules/ingest-geoip/src/main/java/org/elasticsearch/ingest/geoip/DatabaseReaderLazyLoader.java b/modules/ingest-geoip/src/main/java/org/elasticsearch/ingest/geoip/DatabaseReaderLazyLoader.java index 2e79bd3733767..7edcd8242356e 100644 --- a/modules/ingest-geoip/src/main/java/org/elasticsearch/ingest/geoip/DatabaseReaderLazyLoader.java +++ b/modules/ingest-geoip/src/main/java/org/elasticsearch/ingest/geoip/DatabaseReaderLazyLoader.java @@ -210,8 +210,8 @@ String getMd5() { return md5; } - public void close(boolean deleteDatabaseFileOnClose) throws IOException { - this.deleteDatabaseFileOnClose = deleteDatabaseFileOnClose; + public void close(boolean shouldDeleteDatabaseFileOnClose) throws IOException { + this.deleteDatabaseFileOnClose = shouldDeleteDatabaseFileOnClose; close(); } diff --git a/modules/ingest-geoip/src/main/java/org/elasticsearch/ingest/geoip/GeoIpDownloader.java b/modules/ingest-geoip/src/main/java/org/elasticsearch/ingest/geoip/GeoIpDownloader.java index 61a7ef1cd37ef..40cd8ce00a262 100644 --- a/modules/ingest-geoip/src/main/java/org/elasticsearch/ingest/geoip/GeoIpDownloader.java +++ b/modules/ingest-geoip/src/main/java/org/elasticsearch/ingest/geoip/GeoIpDownloader.java @@ -163,7 +163,7 @@ void processDatabase(Map databaseInfo) { if (lastChunk > firstChunk) { state = state.put(name, new Metadata(start, firstChunk, lastChunk - 1, md5, start)); updateTaskState(); - stats = stats.successfulDownload(System.currentTimeMillis() - start).count(state.getDatabases().size()); + stats = stats.successfulDownload(System.currentTimeMillis() - start).databasesCount(state.getDatabases().size()); logger.info("updated geoip database [" + name + "]"); deleteOldChunks(name, firstChunk); } diff --git a/modules/ingest-geoip/src/main/java/org/elasticsearch/ingest/geoip/stats/GeoIpDownloaderStats.java b/modules/ingest-geoip/src/main/java/org/elasticsearch/ingest/geoip/stats/GeoIpDownloaderStats.java index 88b7693f3f5bf..acfda99ae42fc 100644 --- a/modules/ingest-geoip/src/main/java/org/elasticsearch/ingest/geoip/stats/GeoIpDownloaderStats.java +++ b/modules/ingest-geoip/src/main/java/org/elasticsearch/ingest/geoip/stats/GeoIpDownloaderStats.java @@ -135,7 +135,7 @@ public GeoIpDownloaderStats failedDownload() { ); } - public GeoIpDownloaderStats count(int databasesCount) { + public GeoIpDownloaderStats databasesCount(int databasesCount) { return new GeoIpDownloaderStats( successfulDownloads, failedDownloads, diff --git a/modules/ingest-geoip/src/test/java/org/elasticsearch/ingest/geoip/stats/GeoIpDownloaderStatsSerializingTests.java b/modules/ingest-geoip/src/test/java/org/elasticsearch/ingest/geoip/stats/GeoIpDownloaderStatsSerializingTests.java index c290b086dd139..8d13c8e5a199a 100644 --- a/modules/ingest-geoip/src/test/java/org/elasticsearch/ingest/geoip/stats/GeoIpDownloaderStatsSerializingTests.java +++ b/modules/ingest-geoip/src/test/java/org/elasticsearch/ingest/geoip/stats/GeoIpDownloaderStatsSerializingTests.java @@ -32,7 +32,7 @@ protected GeoIpDownloaderStats createTestInstance() { } static GeoIpDownloaderStats createRandomInstance() { - GeoIpDownloaderStats stats = GeoIpDownloaderStats.EMPTY.count(randomInt(1000)); + GeoIpDownloaderStats stats = GeoIpDownloaderStats.EMPTY.databasesCount(randomInt(1000)); int successes = randomInt(20); for (int i = 0; i < successes; i++) { stats = stats.successfulDownload(randomLongBetween(0, 3000)); diff --git a/modules/ingest-user-agent/src/main/java/org/elasticsearch/ingest/useragent/UserAgentParser.java b/modules/ingest-user-agent/src/main/java/org/elasticsearch/ingest/useragent/UserAgentParser.java index 861a46ea819d9..65dac3af76db1 100644 --- a/modules/ingest-user-agent/src/main/java/org/elasticsearch/ingest/useragent/UserAgentParser.java +++ b/modules/ingest-user-agent/src/main/java/org/elasticsearch/ingest/useragent/UserAgentParser.java @@ -190,12 +190,12 @@ public Details parse(String agentString, boolean extractDeviceType) { } private VersionedName findMatch(List possiblePatterns, String agentString) { - VersionedName name; + VersionedName versionedName; for (UserAgentSubpattern pattern : possiblePatterns) { - name = pattern.match(agentString); + versionedName = pattern.match(agentString); - if (name != null) { - return name; + if (versionedName != null) { + return versionedName; } } diff --git a/modules/ingest-user-agent/src/test/java/org/elasticsearch/ingest/useragent/UserAgentProcessorTests.java b/modules/ingest-user-agent/src/test/java/org/elasticsearch/ingest/useragent/UserAgentProcessorTests.java index 52896f65a753d..4da6ac77b50f8 100644 --- a/modules/ingest-user-agent/src/test/java/org/elasticsearch/ingest/useragent/UserAgentProcessorTests.java +++ b/modules/ingest-user-agent/src/test/java/org/elasticsearch/ingest/useragent/UserAgentProcessorTests.java @@ -52,7 +52,7 @@ public static void setupProcessor() throws IOException { } public void testNullValueWithIgnoreMissing() throws Exception { - UserAgentProcessor processor = new UserAgentProcessor( + UserAgentProcessor userAgentProcessor = new UserAgentProcessor( randomAlphaOfLength(10), null, "source_field", @@ -67,12 +67,12 @@ public void testNullValueWithIgnoreMissing() throws Exception { Collections.singletonMap("source_field", null) ); IngestDocument ingestDocument = new IngestDocument(originalIngestDocument); - processor.execute(ingestDocument); + userAgentProcessor.execute(ingestDocument); assertIngestDocument(originalIngestDocument, ingestDocument); } public void testNonExistentWithIgnoreMissing() throws Exception { - UserAgentProcessor processor = new UserAgentProcessor( + UserAgentProcessor userAgentProcessor = new UserAgentProcessor( randomAlphaOfLength(10), null, "source_field", @@ -84,12 +84,12 @@ public void testNonExistentWithIgnoreMissing() throws Exception { ); IngestDocument originalIngestDocument = RandomDocumentPicks.randomIngestDocument(random(), Collections.emptyMap()); IngestDocument ingestDocument = new IngestDocument(originalIngestDocument); - processor.execute(ingestDocument); + userAgentProcessor.execute(ingestDocument); assertIngestDocument(originalIngestDocument, ingestDocument); } public void testNullWithoutIgnoreMissing() throws Exception { - UserAgentProcessor processor = new UserAgentProcessor( + UserAgentProcessor userAgentProcessor = new UserAgentProcessor( randomAlphaOfLength(10), null, "source_field", @@ -104,12 +104,12 @@ public void testNullWithoutIgnoreMissing() throws Exception { Collections.singletonMap("source_field", null) ); IngestDocument ingestDocument = new IngestDocument(originalIngestDocument); - Exception exception = expectThrows(Exception.class, () -> processor.execute(ingestDocument)); + Exception exception = expectThrows(Exception.class, () -> userAgentProcessor.execute(ingestDocument)); assertThat(exception.getMessage(), equalTo("field [source_field] is null, cannot parse user-agent.")); } public void testNonExistentWithoutIgnoreMissing() throws Exception { - UserAgentProcessor processor = new UserAgentProcessor( + UserAgentProcessor userAgentProcessor = new UserAgentProcessor( randomAlphaOfLength(10), null, "source_field", @@ -121,7 +121,7 @@ public void testNonExistentWithoutIgnoreMissing() throws Exception { ); IngestDocument originalIngestDocument = RandomDocumentPicks.randomIngestDocument(random(), Collections.emptyMap()); IngestDocument ingestDocument = new IngestDocument(originalIngestDocument); - Exception exception = expectThrows(Exception.class, () -> processor.execute(ingestDocument)); + Exception exception = expectThrows(Exception.class, () -> userAgentProcessor.execute(ingestDocument)); assertThat(exception.getMessage(), equalTo("field [source_field] not present as part of path [source_field]")); } @@ -303,7 +303,7 @@ public void testExtractDeviceTypeDisabled() { InputStream regexStream = UserAgentProcessor.class.getResourceAsStream("/regexes.yml"); InputStream deviceTypeRegexStream = UserAgentProcessor.class.getResourceAsStream("/device_type_regexes.yml"); UserAgentParser parser = new UserAgentParser(randomAlphaOfLength(10), regexStream, deviceTypeRegexStream, new UserAgentCache(1000)); - UserAgentProcessor processor = new UserAgentProcessor( + UserAgentProcessor userAgentProcessor = new UserAgentProcessor( randomAlphaOfLength(10), null, "source_field", @@ -313,7 +313,7 @@ public void testExtractDeviceTypeDisabled() { false, false ); - processor.execute(ingestDocument); + userAgentProcessor.execute(ingestDocument); Map data = ingestDocument.getSourceAndMetadata(); assertThat(data, hasKey("target_field"));