Details
-
Bug
-
Status: Closed
-
Critical
-
Resolution: Fixed
-
1.1
-
None
-
None
Description
RandomDataImpl.nextInt(Integer.MIN_VALUE, Integer.MAX_VALUE) suffers from overflow errors.
change
return lower + (int) (rand.nextDouble() * (upper - lower + 1));
to
return (int) (lower + (long) (rand.nextDouble()*((long) upper - lower + 1)));
additional checks must be made for the nextlong(long, long) method.
At first I thought about using MathUtils.subAndCheck(long, long) but there is only an int version avalible, and the problem is that subAndCheck internaly uses long values to check for overflow just as my previous channge proposes. The only thing I can think of is using a BigInteger to check for the number of bits required to express the difference.