Duplicate :
|
|
Relates :
|
|
Relates :
|
FULL PRODUCT VERSION : A DESCRIPTION OF THE PROBLEM : When set Integer.MAX_VALUE - 1 to BitSet, then call the toString method. It will throw exception: java.lang.IndexOutOfBoundsException: fromIndex < 0: -2147483648 Test code: public static void main(String[] args) { BitSet bitSet = new BitSet(); bitSet.set(Integer.MAX_VALUE - 1); System.out.println( bitSet.toString()); } The bug was occured at 1189 line of BitSet source. for (i = nextSetBit(i+1); i >= 0; i = nextSetBit(i+1)) { If set Integer.MAX_VALUE to BitSet, exception will throw at the first nextSetBit(i+1). If set Integer.MAX_VALUE - 1 to BitSet, exception will throw at the second nextSetBit(i+1). I think before call nextSetBit(i+1) method, to check i is equal to Integer.MAX_VALUE is better. REPRODUCIBILITY : This bug can be reproduced always.