Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Compare strings with equals() instead of == #16461

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
- Fix typo super->sb in method toString() of RemoteStoreNodeAttribute ([#15362](https://github.com/opensearch-project/OpenSearch/pull/15362))
- [Workload Management] Fixing Create/Update QueryGroup TransportActions to execute from non-cluster manager nodes ([16422](https://github.com/opensearch-project/OpenSearch/pull/16422))
- Fix flaky test in `testApproximateRangeWithSizeOverDefault` by adjusting totalHits assertion logic ([#16434](https://github.com/opensearch-project/OpenSearch/pull/16434#pullrequestreview-2386999409))
- Fix string equality comparisons ([#16461](https://github.com/opensearch-project/OpenSearch/pull/16461))

### Security

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
import java.util.Collection;
import java.util.HashSet;
import java.util.List;
import java.util.Objects;
import java.util.Set;

/**
Expand Down Expand Up @@ -105,7 +106,7 @@ public List<String> 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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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]);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,11 +91,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 && ShingleFilter.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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 (indexMetadata.getSettings().getAsBoolean(IndexMetadata.SETTING_REMOTE_STORE_ENABLED, false)) {
nodeSettings = Settings.builder()
.put("node.name", routing.currentNodeId())
.put("node.attr.remote_store.translog.repository", "seg_repo")
Expand Down
Loading