Documenting that IndexReaderContext#leaves() will never return a null value and remove the null checks from the method calls (#12034)

This commit is contained in:
Erik Pellizzon 2023-01-06 23:35:52 +01:00 committed by GitHub
parent 5fccaec166
commit e14327288e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 6 additions and 15 deletions

View File

@ -197,6 +197,8 @@ Improvements
* GITHUB#12016: Upgrade lucene/expressions to use antlr 4.11.1 (Andriy Redko) * GITHUB#12016: Upgrade lucene/expressions to use antlr 4.11.1 (Andriy Redko)
* GITHUB#12034: Remove null check in IndexReaderContext#leaves() usages (Erik Pellizzon)
Bug Fixes Bug Fixes
--------------------- ---------------------
* GITHUB#11726: Indexing term vectors on large documents could fail due to * GITHUB#11726: Indexing term vectors on large documents could fail due to

View File

@ -64,7 +64,8 @@ public abstract class IndexReaderContext {
/** /**
* Returns the context's leaves if this context is a top-level context. For convenience, if this * Returns the context's leaves if this context is a top-level context. For convenience, if this
* is an {@link LeafReaderContext} this returns itself as the only leaf. * is an {@link LeafReaderContext} this returns itself as the only leaf, and it will never return
* a null value.
* *
* <p>Note: this is convenience method since leaves can always be obtained by walking the context * <p>Note: this is convenience method since leaves can always be obtained by walking the context
* tree using {@link #children()}. * tree using {@link #children()}.

View File

@ -49,13 +49,7 @@ public final class TermStates {
topReaderContextIdentity = context.identity; topReaderContextIdentity = context.identity;
docFreq = 0; docFreq = 0;
totalTermFreq = 0; totalTermFreq = 0;
final int len; states = new TermState[context.leaves().size()];
if (context.leaves() == null) {
len = 1;
} else {
len = context.leaves().size();
}
states = new TermState[len];
this.term = term; this.term = term;
} }

View File

@ -314,14 +314,8 @@ public final class BlendedTermQuery extends Query {
IndexReaderContext readerContext, TermStates ctx, int artificialDf, long artificialTtf) IndexReaderContext readerContext, TermStates ctx, int artificialDf, long artificialTtf)
throws IOException { throws IOException {
List<LeafReaderContext> leaves = readerContext.leaves(); List<LeafReaderContext> leaves = readerContext.leaves();
final int len;
if (leaves == null) {
len = 1;
} else {
len = leaves.size();
}
TermStates newCtx = new TermStates(readerContext); TermStates newCtx = new TermStates(readerContext);
for (int i = 0; i < len; ++i) { for (int i = 0; i < leaves.size(); ++i) {
TermState termState = ctx.get(leaves.get(i)); TermState termState = ctx.get(leaves.get(i));
if (termState == null) { if (termState == null) {
continue; continue;