From d779fc65064bfd2dbbeffa4f5348541545c78375 Mon Sep 17 00:00:00 2001 From: Dmitry Kryukov Date: Mon, 21 Oct 2024 22:27:46 +0300 Subject: [PATCH] Compare strings with equals() instead of == Signed-off-by: Dmitry Kryukov --- .../cluster/metadata/IndexAbstractionResolver.java | 3 ++- .../common/lucene/search/MultiPhrasePrefixQuery.java | 2 +- .../bucket/composite/UnsignedLongValuesSource.java | 2 +- .../search/suggest/phrase/NoisyChannelSpellChecker.java | 6 ++++-- .../java/org/opensearch/index/shard/IndexShardTestCase.java | 2 +- 5 files changed, 9 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 5563511aa8d45..9332638e7001a 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 @@ -126,7 +126,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..78bc6d22acb93 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 @@ -45,6 +45,8 @@ import java.util.ArrayList; import java.util.List; +import static org.apache.lucene.analysis.shingle.ShingleFilter.DEFAULT_TOKEN_TYPE; + /** * Spell checker based on a noisy channel * @@ -91,11 +93,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 && DEFAULT_TOKEN_TYPE.equals(typeAttribute.type())) { return; } anyUnigram = true; - if (posIncAttr.getPositionIncrement() == 0 && typeAttribute.type() == SynonymFilter.TYPE_SYNONYM) { + if (posIncAttr.getPositionIncrement() == 0 && SynonymFilter.TYPE_SYNONYM.equals(typeAttribute.type())) { 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..b71eadd21dc59 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 (Boolean.parseBoolean(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")