Index: lucene/src/java/org/apache/lucene/util/OpenBitSet.java =================================================================== --- lucene/src/java/org/apache/lucene/util/OpenBitSet.java (revision 1125975) +++ lucene/src/java/org/apache/lucene/util/OpenBitSet.java (working copy) @@ -78,11 +78,15 @@ protected long[] bits; protected int wlen; // number of words (elements) used in the array + // Used only for assert: + private long numBits; + /** Constructs an OpenBitSet large enough to hold numBits. * * @param numBits */ public OpenBitSet(long numBits) { + this.numBits = numBits; bits = new long[bits2words(numBits)]; wlen = bits.length; } @@ -107,6 +111,7 @@ public OpenBitSet(long[] bits, int numWords) { this.bits = bits; this.wlen = numWords; + this.numBits = wlen * 64; } @Override @@ -170,6 +175,7 @@ * The index should be less than the OpenBitSet size */ public boolean fastGet(int index) { + assert index >= 0 && index < numBits; int i = index >> 6; // div 64 // signed shift will keep a negative index and force an // array-index-out-of-bounds-exception, removing the need for an explicit check. @@ -194,6 +200,7 @@ * The index should be less than the OpenBitSet size. */ public boolean fastGet(long index) { + assert index >= 0 && index < numBits; int i = (int)(index >> 6); // div 64 int bit = (int)index & 0x3f; // mod 64 long bitmask = 1L << bit; @@ -217,6 +224,7 @@ * The index should be less than the OpenBitSet size */ public int getBit(int index) { + assert index >= 0 && index < numBits; int i = index >> 6; // div 64 int bit = index & 0x3f; // mod 64 return ((int)(bits[i]>>>bit)) & 0x01; @@ -245,6 +253,7 @@ * The index should be less than the OpenBitSet size. */ public void fastSet(int index) { + assert index >= 0 && index < numBits; int wordNum = index >> 6; // div 64 int bit = index & 0x3f; // mod 64 long bitmask = 1L << bit; @@ -255,6 +264,7 @@ * The index should be less than the OpenBitSet size. */ public void fastSet(long index) { + assert index >= 0 && index < numBits; int wordNum = (int)(index >> 6); int bit = (int)index & 0x3f; long bitmask = 1L << bit; @@ -296,6 +306,7 @@ ensureCapacity(index+1); wlen = wordNum+1; } + numBits = Math.max(numBits, index+1); return wordNum; } @@ -304,6 +315,7 @@ * The index should be less than the OpenBitSet size. */ public void fastClear(int index) { + assert index >= 0 && index < numBits; int wordNum = index >> 6; int bit = index & 0x03f; long bitmask = 1L << bit; @@ -321,6 +333,7 @@ * The index should be less than the OpenBitSet size. */ public void fastClear(long index) { + assert index >= 0 && index < numBits; int wordNum = (int)(index >> 6); // div 64 int bit = (int)index & 0x3f; // mod 64 long bitmask = 1L << bit; @@ -415,6 +428,7 @@ * The index should be less than the OpenBitSet size. */ public boolean getAndSet(int index) { + assert index >= 0 && index < numBits; int wordNum = index >> 6; // div 64 int bit = index & 0x3f; // mod 64 long bitmask = 1L << bit; @@ -427,6 +441,7 @@ * The index should be less than the OpenBitSet size. */ public boolean getAndSet(long index) { + assert index >= 0 && index < numBits; int wordNum = (int)(index >> 6); // div 64 int bit = (int)index & 0x3f; // mod 64 long bitmask = 1L << bit; @@ -439,6 +454,7 @@ * The index should be less than the OpenBitSet size. */ public void fastFlip(int index) { + assert index >= 0 && index < numBits; int wordNum = index >> 6; // div 64 int bit = index & 0x3f; // mod 64 long bitmask = 1L << bit; @@ -449,6 +465,7 @@ * The index should be less than the OpenBitSet size. */ public void fastFlip(long index) { + assert index >= 0 && index < numBits; int wordNum = (int)(index >> 6); // div 64 int bit = (int)index & 0x3f; // mod 64 long bitmask = 1L << bit; @@ -467,6 +484,7 @@ * The index should be less than the OpenBitSet size. */ public boolean flipAndGet(int index) { + assert index >= 0 && index < numBits; int wordNum = index >> 6; // div 64 int bit = index & 0x3f; // mod 64 long bitmask = 1L << bit; @@ -478,6 +496,7 @@ * The index should be less than the OpenBitSet size. */ public boolean flipAndGet(long index) { + assert index >= 0 && index < numBits; int wordNum = (int)(index >> 6); // div 64 int bit = (int)index & 0x3f; // mod 64 long bitmask = 1L << bit; @@ -674,6 +693,7 @@ public void union(OpenBitSet other) { int newLen = Math.max(wlen,other.wlen); ensureCapacityWords(newLen); + numBits = Math.max(other.numBits, numBits); long[] thisArr = this.bits; long[] otherArr = other.bits; @@ -702,6 +722,7 @@ public void xor(OpenBitSet other) { int newLen = Math.max(wlen,other.wlen); ensureCapacityWords(newLen); + numBits = Math.max(other.numBits, numBits); long[] thisArr = this.bits; long[] otherArr = other.bits;