From bcaa52c5629537ee3f5d746ae7b2b61180bc9e73 Mon Sep 17 00:00:00 2001 From: Uwe Schindler Date: Sun, 17 Jun 2012 17:22:28 +0000 Subject: [PATCH] The base calculation in ReaderUtil.Gather is so complicated, add some assert to verify that it is still correct. The code lead to another bug I fixed in CompositeReaderContext long time ago (at least it explains why Simon did it wrong...) git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1351129 13f79535-47bb-0310-9956-ffa450edef68 --- .../apache/lucene/index/CompositeReaderContext.java | 1 + .../src/java/org/apache/lucene/util/ReaderUtil.java | 11 ++++++----- 2 files changed, 7 insertions(+), 5 deletions(-) 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;