You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by pa...@apache.org on 2023/01/06 23:07:07 UTC
[lucene] branch branch_9x updated: Documenting that IndexReaderContext#leaves() will never return a null value and remove the null checks from the method calls (#12034)
This is an automated email from the ASF dual-hosted git repository.
patrickz pushed a commit to branch branch_9x
in repository https://gitbox.apache.org/repos/asf/lucene.git
The following commit(s) were added to refs/heads/branch_9x by this push:
new eac4da8eb01 Documenting that IndexReaderContext#leaves() will never return a null value and remove the null checks from the method calls (#12034)
eac4da8eb01 is described below
commit eac4da8eb01a6394c912288f4a308850f17eef0e
Author: Erik Pellizzon <er...@gmail.com>
AuthorDate: Fri Jan 6 23:35:52 2023 +0100
Documenting that IndexReaderContext#leaves() will never return a null value and remove the null checks from the method calls (#12034)
---
lucene/CHANGES.txt | 2 ++
.../core/src/java/org/apache/lucene/index/IndexReaderContext.java | 3 ++-
lucene/core/src/java/org/apache/lucene/index/TermStates.java | 8 +-------
.../core/src/java/org/apache/lucene/search/BlendedTermQuery.java | 8 +-------
4 files changed, 6 insertions(+), 15 deletions(-)
diff --git a/lucene/CHANGES.txt b/lucene/CHANGES.txt
index 252a1e13239..d1802e42dea 100644
--- a/lucene/CHANGES.txt
+++ b/lucene/CHANGES.txt
@@ -103,6 +103,8 @@ Improvements
* 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
---------------------
* GITHUB#11726: Indexing term vectors on large documents could fail due to
diff --git a/lucene/core/src/java/org/apache/lucene/index/IndexReaderContext.java b/lucene/core/src/java/org/apache/lucene/index/IndexReaderContext.java
index f39c2746cab..fbc59e3d1ca 100644
--- a/lucene/core/src/java/org/apache/lucene/index/IndexReaderContext.java
+++ b/lucene/core/src/java/org/apache/lucene/index/IndexReaderContext.java
@@ -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
- * 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
* tree using {@link #children()}.
diff --git a/lucene/core/src/java/org/apache/lucene/index/TermStates.java b/lucene/core/src/java/org/apache/lucene/index/TermStates.java
index d1c10401190..bf4b97e86e5 100644
--- a/lucene/core/src/java/org/apache/lucene/index/TermStates.java
+++ b/lucene/core/src/java/org/apache/lucene/index/TermStates.java
@@ -49,13 +49,7 @@ public final class TermStates {
topReaderContextIdentity = context.identity;
docFreq = 0;
totalTermFreq = 0;
- final int len;
- if (context.leaves() == null) {
- len = 1;
- } else {
- len = context.leaves().size();
- }
- states = new TermState[len];
+ states = new TermState[context.leaves().size()];
this.term = term;
}
diff --git a/lucene/core/src/java/org/apache/lucene/search/BlendedTermQuery.java b/lucene/core/src/java/org/apache/lucene/search/BlendedTermQuery.java
index e9a135f88d3..8b73eb5b27a 100644
--- a/lucene/core/src/java/org/apache/lucene/search/BlendedTermQuery.java
+++ b/lucene/core/src/java/org/apache/lucene/search/BlendedTermQuery.java
@@ -314,14 +314,8 @@ public final class BlendedTermQuery extends Query {
IndexReaderContext readerContext, TermStates ctx, int artificialDf, long artificialTtf)
throws IOException {
List<LeafReaderContext> leaves = readerContext.leaves();
- final int len;
- if (leaves == null) {
- len = 1;
- } else {
- len = leaves.size();
- }
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));
if (termState == null) {
continue;