-
Bug
-
Resolution: Won't Fix
-
P4
-
None
-
11, 13, 14
-
generic
-
generic
A DESCRIPTION OF THE PROBLEM :
Because the return type of the method BitSet#size is int, so the method may return a negative value in some case, for example, will return -2147483648.
```
BitSet bitSet = new BitSet(Integer.MAX_VALUE);
for (int i = 0; i < Integer.MAX_VALUE - 1000; i++) {
bitSet.set(i);
}
System.out.println(bitSet.size());
```
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
BitSet bitSet = new BitSet(Integer.MAX_VALUE);
for (int i = 0; i < Integer.MAX_VALUE - 1000; i++) {
bitSet.set(i);
}
System.out.println(bitSet.size());
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
137438953408
ACTUAL -
-2147483648
---------- BEGIN SOURCE ----------
public class TestBitSetSize {
public static void main(String[] args) throws Exception {
java.util.BitSet bitSet = new java.util.BitSet(Integer.MAX_VALUE);
for (int i = 0; i < Integer.MAX_VALUE - 1000; i++) {
bitSet.set(i);
}
System.out.println(bitSet.size());
}
}
---------- END SOURCE ----------
CUSTOMER SUBMITTED WORKAROUND :
change the return type int to long
FREQUENCY : always
Because the return type of the method BitSet#size is int, so the method may return a negative value in some case, for example, will return -2147483648.
```
BitSet bitSet = new BitSet(Integer.MAX_VALUE);
for (int i = 0; i < Integer.MAX_VALUE - 1000; i++) {
bitSet.set(i);
}
System.out.println(bitSet.size());
```
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
BitSet bitSet = new BitSet(Integer.MAX_VALUE);
for (int i = 0; i < Integer.MAX_VALUE - 1000; i++) {
bitSet.set(i);
}
System.out.println(bitSet.size());
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
137438953408
ACTUAL -
-2147483648
---------- BEGIN SOURCE ----------
public class TestBitSetSize {
public static void main(String[] args) throws Exception {
java.util.BitSet bitSet = new java.util.BitSet(Integer.MAX_VALUE);
for (int i = 0; i < Integer.MAX_VALUE - 1000; i++) {
bitSet.set(i);
}
System.out.println(bitSet.size());
}
}
---------- END SOURCE ----------
CUSTOMER SUBMITTED WORKAROUND :
change the return type int to long
FREQUENCY : always
- relates to
-
JDK-4213570 java.util.BitSet.size() is not 100% backward-compatible from 1.2 to 1.1.x
-
- Closed
-
-
JDK-8305734 BitSet.get(int, int) always returns the empty BitSet when the Integer.MAX VALUE is set
-
- Open
-