add assert to catch mismatched delete count on write; add detail to exception messages on corruption

git-svn-id: https://svn.apache.org/repos/asf/lucene/java/trunk@907781 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Michael McCandless 2010-02-08 20:31:25 +00:00
parent b4ac5029e0
commit 0a07c2a1fd
3 changed files with 4 additions and 3 deletions

View File

@ -533,6 +533,7 @@ public final class SegmentInfo {
*/ */
void write(IndexOutput output) void write(IndexOutput output)
throws IOException { throws IOException {
assert delCount <= docCount: "delCount=" + delCount + " docCount=" + docCount + " segment=" + name;
output.writeString(name); output.writeString(name);
output.writeInt(docCount); output.writeInt(docCount);
output.writeLong(delGen); output.writeLong(delGen);

View File

@ -613,7 +613,7 @@ public class SegmentReader extends IndexReader implements Cloneable {
deletedDocsRef = new AtomicInteger(1); deletedDocsRef = new AtomicInteger(1);
assert checkDeletedCounts(); assert checkDeletedCounts();
if (deletedDocs.size() != si.docCount) { if (deletedDocs.size() != si.docCount) {
throw new CorruptIndexException("document count mismatch: deleted docs count " + deletedDocs.size() + " vs segment doc count " + si.docCount); throw new CorruptIndexException("document count mismatch: deleted docs count " + deletedDocs.size() + " vs segment doc count " + si.docCount + " segment=" + si.name);
} }
} else } else
assert si.getDelCount() == 0; assert si.getDelCount() == 0;

View File

@ -63,7 +63,7 @@ public final class BitVector implements Cloneable {
/** Sets the value of <code>bit</code> to one. */ /** Sets the value of <code>bit</code> to one. */
public final void set(int bit) { public final void set(int bit) {
if (bit >= size) { if (bit >= size) {
throw new ArrayIndexOutOfBoundsException(bit); throw new ArrayIndexOutOfBoundsException("bit=" + bit + " size=" + size);
} }
bits[bit >> 3] |= 1 << (bit & 7); bits[bit >> 3] |= 1 << (bit & 7);
count = -1; count = -1;
@ -73,7 +73,7 @@ public final class BitVector implements Cloneable {
* returns true if bit was already set */ * returns true if bit was already set */
public final boolean getAndSet(int bit) { public final boolean getAndSet(int bit) {
if (bit >= size) { if (bit >= size) {
throw new ArrayIndexOutOfBoundsException(bit); throw new ArrayIndexOutOfBoundsException("bit=" + bit + " size=" + size);
} }
final int pos = bit >> 3; final int pos = bit >> 3;
final int v = bits[pos]; final int v = bits[pos];