Unnecessary Check and Assgiment at FieldFacetStats [LUCENE-5508]
- 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
Assessment
This issue has not been assessed yet.