-
Type:
Bug
-
Status: Closed
-
Priority:
P4
-
Resolution: Won't Fix
-
Affects Version/s: 11, 13, 14
-
Fix Version/s: None
-
Component/s: core-libs
-
Labels:
-
Subcomponent:
-
CPU:generic
-
OS: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
-