-
Bug
-
Resolution: Fixed
-
P4
-
17, 18, 19
-
b20
-
generic
-
generic
A DESCRIPTION OF THE PROBLEM :
RandomGenerator:
default double nextDouble(double origin, double bound);
https://docs.oracle.com/en/java/javase/17/docs/api/java.base/java/util/random/RandomGenerator.html#nextDouble(double,double)
default float nextFloat(float origin, float bound);
https://docs.oracle.com/en/java/javase/17/docs/api/java.base/java/util/random/RandomGenerator.html#nextFloat(float,float)
These methods are documented incorrectly. The default method checks (origin < bound) and (bound - origin) < +infinity.
The exception conditions are incorrect:
"if {@code origin} is not finite,
or {@code bound} is not finite, or {@code origin}
is greater than or equal to {@code bound}"
This is not true. Calling with -Double.MAX_VALUE and Double.MAX_VALUE satisfies the documented requirements but actually throws an exception.
The implementation spec is incorrect:
The default implementation checks that {@code origin} and
{@code bound} are positive finite doubles.
This is not true. Origin and Bound can be negative.
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
import java.util.random.*;
public class NextDoubleBug {
public static void main(String[] args) {
RandomGenerator g = RandomGeneratorFactory.of("L64X128MixRandom").create(42);
System.out.printf("Negative origin and bound are OK: %s%n", g.nextDouble(-10, -5));
try {
g.nextDouble(-Double.MAX_VALUE, Double.MAX_VALUE);
throw new IllegalStateException("Infinite range should throw");
} catch (IllegalArgumentException expected) {
System.out.println("Infinite range throws");
}
}
}
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
> java NextDoubleBug
Negative origin and bound are OK: -6.5179306489351125
Infinite range throws
ACTUAL -
The result is as expected. This does not match the javadoc behaviour.
---------- BEGIN SOURCE ----------
Provided
---------- END SOURCE ----------
FREQUENCY : always
RandomGenerator:
default double nextDouble(double origin, double bound);
https://docs.oracle.com/en/java/javase/17/docs/api/java.base/java/util/random/RandomGenerator.html#nextDouble(double,double)
default float nextFloat(float origin, float bound);
https://docs.oracle.com/en/java/javase/17/docs/api/java.base/java/util/random/RandomGenerator.html#nextFloat(float,float)
These methods are documented incorrectly. The default method checks (origin < bound) and (bound - origin) < +infinity.
The exception conditions are incorrect:
"if {@code origin} is not finite,
or {@code bound} is not finite, or {@code origin}
is greater than or equal to {@code bound}"
This is not true. Calling with -Double.MAX_VALUE and Double.MAX_VALUE satisfies the documented requirements but actually throws an exception.
The implementation spec is incorrect:
The default implementation checks that {@code origin} and
{@code bound} are positive finite doubles.
This is not true. Origin and Bound can be negative.
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
import java.util.random.*;
public class NextDoubleBug {
public static void main(String[] args) {
RandomGenerator g = RandomGeneratorFactory.of("L64X128MixRandom").create(42);
System.out.printf("Negative origin and bound are OK: %s%n", g.nextDouble(-10, -5));
try {
g.nextDouble(-Double.MAX_VALUE, Double.MAX_VALUE);
throw new IllegalStateException("Infinite range should throw");
} catch (IllegalArgumentException expected) {
System.out.println("Infinite range throws");
}
}
}
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
> java NextDoubleBug
Negative origin and bound are OK: -6.5179306489351125
Infinite range throws
ACTUAL -
The result is as expected. This does not match the javadoc behaviour.
---------- BEGIN SOURCE ----------
Provided
---------- END SOURCE ----------
FREQUENCY : always
- csr for
-
JDK-8283693 RandomGenerator nextDouble(double, double) is documented incorrectly
-
- Closed
-
- relates to
-
JDK-8288288 JDK-8202449 fix breaks RandomGenerator.html#nextDouble(double,double) conformance spec for IAEx case
-
- Closed
-