BitSet.java has some invariants, which can be understood best using
this java code:
private void checkInvariants() {
assert(wordsInUse == 0 || words[wordsInUse - 1] != 0);
assert(wordsInUse >= 0 && wordsInUse <= words.length);
assert(wordsInUse == words.length || words[wordsInUse] == 0);
}
But these invariants do not always hold, leading to corrupt internal
data corruption and incorrect results.
One manifestation is this program:
-------------------------------------------------------------------
import java.util.*;
public class Bug {
public static void main(String[] args) throws Exception {
BitSet s = new BitSet();
s.set(127,127);
System.out.printf("length=%d isEmpty=%b%n", s.length(), s.isEmpty());
}
}
-------------------------------------------------------------------
Giving:
length=64 isEmpty=false
when correct is:
length=0 isEmpty=true
###@###.### 2005-1-27 06:57:58 GMT
###@###.### 2005-1-27 07:01:50 GMT