apache / apache/lucene

Unnecessary Check and Assgiment at FieldFacetStats [LUCENE-5508]

Open
#6,571 3 comments 0 reactions 0 assignees View on GitHub
affects-version:4.6.1 affects-version:4.7 legacy-jira-fix-version:4.9 legacy-jira-fix-version:6.0 legacy-jira-priority:Minor type:bug
Dominant language
Java
Stars
3.6k
Forks
1.4k
Avg merge
2d 11h
Merged PRs (30d)
88

Description

Here is the code:

```Java
int term = topLevelSortedValues.getOrd(docID);
int arrIdx = term;
if (arrIdx >= 0 && arrIdx < topLevelSortedValues.getValueCount()) {
final BytesRef br;
if (term == -1) {
br = null;
} else {
br = tempBR;
topLevelSortedValues.lookupOrd(term, tempBR);
}
String key = br == null ? null : br.utf8ToString();
while (facetStatsTerms.size() <= statsTermNum) {
facetStatsTerms.add(new HashMap());
}
final Map statsTermCounts = facetStatsTerms.get(statsTermNum);
Integer statsTermCount = statsTermCounts.get(key);
if (statsTermCount == null) {
statsTermCounts.put(key, 1);
} else {
statsTermCounts.put(key, statsTermCount + 1);
}
return true;
}
```

There is a check condition for:

```Java
arrIdx >= 0
```

but there is an unnecessary check condition after it:

```Java
if (term == -1) {
br = null;
} else {
br = tempBR;
topLevelSortedValues.lookupOrd(term, tempBR);
}
```

because arrIdx is equals to term and greater or equals to 0 within that code part.

---
Migrated from [LUCENE-5508](https://issues.apache.org/jira/browse/LUCENE-5508) by Furkan Kamaci, updated May 09 2016
Attachments: [LUCENE-5508.patch](https://apache.github.io/lucene-jira-archive/attachments/LUCENE-5508/LUCENE-5508.patch)

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.