From 1a355fd28a66ba6c778297ed28305da8d2d89d18 Mon Sep 17 00:00:00 2001 From: Dmitry Kryukov Date: Thu, 22 Aug 2024 20:51:11 +0300 Subject: [PATCH] Compare strings with equals() instead of == --- .../cluster/metadata/IndexAbstractionResolver.java | 3 ++- .../common/lucene/search/MultiPhrasePrefixQuery.java | 2 +- .../bucket/composite/UnsignedLongValuesSource.java | 2 +- .../search/suggest/phrase/NoisyChannelSpellChecker.java | 5 +++-- .../java/org/opensearch/index/shard/IndexShardTestCase.java | 2 +- 5 files changed, 8 insertions(+), 6 deletions(-) diff --git a/server/src/main/java/org/opensearch/cluster/metadata/IndexAbstractionResolver.java b/server/src/main/java/org/opensearch/cluster/metadata/IndexAbstractionResolver.java index a83c778a4b83a..2229f260bc6dc 100644 --- a/server/src/main/java/org/opensearch/cluster/metadata/IndexAbstractionResolver.java +++ b/server/src/main/java/org/opensearch/cluster/metadata/IndexAbstractionResolver.java @@ -41,6 +41,7 @@ import java.util.Collection; import java.util.HashSet; import java.util.List; +import java.util.Objects; import java.util.Set; /** @@ -105,7 +106,7 @@ public List resolveIndexAbstractions( // we always need to check for date math expressions final String dateMathName = indexNameExpressionResolver.resolveDateMathExpression(indexAbstraction); - if (dateMathName != indexAbstraction) { + if (!Objects.equals(dateMathName, indexAbstraction)) { assert dateMathName.equals(indexAbstraction) == false; if (replaceWildcards && Regex.isSimpleMatchPattern(dateMathName)) { // continue diff --git a/server/src/main/java/org/opensearch/common/lucene/search/MultiPhrasePrefixQuery.java b/server/src/main/java/org/opensearch/common/lucene/search/MultiPhrasePrefixQuery.java index cc0468efb243e..b168936d99c3d 100644 --- a/server/src/main/java/org/opensearch/common/lucene/search/MultiPhrasePrefixQuery.java +++ b/server/src/main/java/org/opensearch/common/lucene/search/MultiPhrasePrefixQuery.java @@ -128,7 +128,7 @@ public void add(Term[] terms) { */ public void add(Term[] terms, int position) { for (int i = 0; i < terms.length; i++) { - if (terms[i].field() != field) { + if (!Objects.equals(terms[i].field(), field)) { throw new IllegalArgumentException("All phrase terms must be in the same field (" + field + "): " + terms[i]); } } diff --git a/server/src/main/java/org/opensearch/search/aggregations/bucket/composite/UnsignedLongValuesSource.java b/server/src/main/java/org/opensearch/search/aggregations/bucket/composite/UnsignedLongValuesSource.java index 797b61f46240e..bb25a121fb048 100644 --- a/server/src/main/java/org/opensearch/search/aggregations/bucket/composite/UnsignedLongValuesSource.java +++ b/server/src/main/java/org/opensearch/search/aggregations/bucket/composite/UnsignedLongValuesSource.java @@ -210,7 +210,7 @@ SortedDocsProducer createSortedDocsProducerOrNull(IndexReader reader, Query quer if (fieldType instanceof NumberFieldMapper.NumberFieldType) { NumberFieldMapper.NumberFieldType ft = (NumberFieldMapper.NumberFieldType) fieldType; - if (ft.typeName() == "unsigned_long") { + if ("unsigned_long".equals(ft.typeName())) { return new UnsignedLongPointsSortedDocsProducer(fieldType.name(), lowerPoint, upperPoint); } } diff --git a/server/src/main/java/org/opensearch/search/suggest/phrase/NoisyChannelSpellChecker.java b/server/src/main/java/org/opensearch/search/suggest/phrase/NoisyChannelSpellChecker.java index e8ba90f353f02..6dd08540641cb 100644 --- a/server/src/main/java/org/opensearch/search/suggest/phrase/NoisyChannelSpellChecker.java +++ b/server/src/main/java/org/opensearch/search/suggest/phrase/NoisyChannelSpellChecker.java @@ -44,6 +44,7 @@ import java.io.IOException; import java.util.ArrayList; import java.util.List; +import java.util.Objects; /** * Spell checker based on a noisy channel @@ -91,11 +92,11 @@ public void reset(TokenStream stream) { public void nextToken() throws IOException { anyTokens = true; BytesRef term = fillBytesRef(termsRef); - if (requireUnigram && typeAttribute.type() == ShingleFilter.DEFAULT_TOKEN_TYPE) { + if (requireUnigram && Objects.equals(typeAttribute.type(), ShingleFilter.DEFAULT_TOKEN_TYPE)) { return; } anyUnigram = true; - if (posIncAttr.getPositionIncrement() == 0 && typeAttribute.type() == SynonymFilter.TYPE_SYNONYM) { + if (posIncAttr.getPositionIncrement() == 0 && Objects.equals(typeAttribute.type(), SynonymFilter.TYPE_SYNONYM)) { assert currentSet != null; TermStats termStats = generator.termStats(term); if (termStats.docFreq > 0) { diff --git a/test/framework/src/main/java/org/opensearch/index/shard/IndexShardTestCase.java b/test/framework/src/main/java/org/opensearch/index/shard/IndexShardTestCase.java index 655a9eb7d5d38..e50ca43d67f03 100644 --- a/test/framework/src/main/java/org/opensearch/index/shard/IndexShardTestCase.java +++ b/test/framework/src/main/java/org/opensearch/index/shard/IndexShardTestCase.java @@ -622,7 +622,7 @@ protected IndexShard newShard( Settings nodeSettings = Settings.builder().put("node.name", routing.currentNodeId()).build(); DiscoveryNodes discoveryNodes = IndexShardTestUtils.getFakeDiscoveryNodes(routing); // To simulate that the node is remote backed - if (indexMetadata.getSettings().get(IndexMetadata.SETTING_REMOTE_STORE_ENABLED) == "true") { + if ("true".equals(indexMetadata.getSettings().get(IndexMetadata.SETTING_REMOTE_STORE_ENABLED))) { nodeSettings = Settings.builder() .put("node.name", routing.currentNodeId()) .put("node.attr.remote_store.translog.repository", "seg_repo")