diff --git a/lucene/core/src/java/org/apache/lucene/index/CompositeReaderContext.java b/lucene/core/src/java/org/apache/lucene/index/CompositeReaderContext.java index 6934b3d848a..55dd2fcd8ee 100644 --- a/lucene/core/src/java/org/apache/lucene/index/CompositeReaderContext.java +++ b/lucene/core/src/java/org/apache/lucene/index/CompositeReaderContext.java @@ -111,6 +111,7 @@ public final class CompositeReaderContext extends IndexReaderContext { children[i] = build(newParent, sequentialSubReaders[i], i, newDocBase); newDocBase += sequentialSubReaders[i].maxDoc(); } + assert newDocBase == cr.maxDoc(); return newParent; } } diff --git a/lucene/core/src/java/org/apache/lucene/util/ReaderUtil.java b/lucene/core/src/java/org/apache/lucene/util/ReaderUtil.java index c44618e662a..d3a7b1a04ac 100644 --- a/lucene/core/src/java/org/apache/lucene/util/ReaderUtil.java +++ b/lucene/core/src/java/org/apache/lucene/util/ReaderUtil.java @@ -101,20 +101,21 @@ public final class ReaderUtil { return run(docBase, topReader); } - private int run(int base, IndexReader reader) throws IOException { + private int run(final int base, final IndexReader reader) throws IOException { if (reader instanceof AtomicReader) { // atomic reader add(base, (AtomicReader) reader); - base += reader.maxDoc(); + return base + reader.maxDoc(); } else { assert reader instanceof CompositeReader : "must be a composite reader"; + int newBase = base; IndexReader[] subReaders = ((CompositeReader) reader).getSequentialSubReaders(); for (int i = 0; i < subReaders.length; i++) { - base = run(base, subReaders[i]); + newBase = run(newBase, subReaders[i]); } + assert newBase == base + reader.maxDoc(); + return newBase; } - - return base; } protected abstract void add(int base, AtomicReader r) throws IOException;