Name: rmT116609 Date: 05/19/2004
FULL PRODUCT VERSION :
java version "1.4.2_04"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.2_04-b05)
Java HotSpot(TM) Client VM (build 1.4.2_04-b05, mixed mode)
java version "1.5.0-beta"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0-beta-b32c)
Java HotSpot(TM) Client VM (build 1.5.0-beta-b32c, mixed mode)
ADDITIONAL OS VERSION INFORMATION :
Linux escher.nz.reeltwo.com 2.4.22-1.2140.nptl #1 Tue Jan 6 20:20:43 EST 2004 i686 i686 i386 GNU/Linux
Solaris 2.9
A DESCRIPTION OF THE PROBLEM :
The constructor BigInteger(int numBits, Random rnd) fails with NegativeArraySizeException when numBits is Integer.MAX_VALUE. What it should do (according to the docs) is produce a BigInteger with 2^31-1 bits (i.e. a very large number).
In fact sizes Integer.MAX_VALUE-1, Integer.MAX_VALUE-2, down to Integer.MAX_VALUE-6 also cause this problem. Integer.MAX_VALUE-7 works as expected.
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Calling the constructor with the indicated arguments causes the problem.
The sample code below demonstrates the problem.
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
I expect a random BigInteger with the specified number of bits to be constructed.
ACTUAL -
Exception.
ERROR MESSAGES/STACK TRACES THAT OCCUR :
escher[sean]:src> !ja
java -Xmx800m Bug
Exception in thread "main" java.lang.NegativeArraySizeException
at java.math.BigInteger.randomBits(BigInteger.java:471)
at java.math.BigInteger.<init>(BigInteger.java:464)
at Bug.main(Bug.java:7)
REPRODUCIBILITY :
This bug can be reproduced always.
---------- BEGIN SOURCE ----------
import java.util.Random;
import java.math.BigInteger;
public class Bug {
public static void main(String[] args) {
BigInteger a = new BigInteger(Integer.MAX_VALUE, new Random());
}
}
---------- END SOURCE ----------
(Incident Review ID: 270492)
======================================================================
###@###.### 10/21/04 01:45 GMT