Name: gm110360 Date: 03/18/2002
FULL PRODUCT VERSION :
java version "1.4.0"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.0-b92)
Java HotSpot(TM) Client VM (build 1.4.0-b92, mixed mode)
FULL OPERATING SYSTEM VERSION :
Microsoft Windows XP [Version 5.1.2600]
A DESCRIPTION OF THE PROBLEM :
Passing Ingeter.MAX_VALUE to BigInteger.isPossiblePrime
causes all numbers to be seen a Prime.
However it may be that the JavaDoc needs
to explicitly state that Integer.MAX_VALUE is not a valid
value.
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
1. see code
EXPECTED VERSUS ACTUAL BEHAVIOR :
new BigInteger("4").isProbablePrime(n) should result in a
return value of "false". It does except when "n"
is "Integer.MAX_VALUE". The expected value is "true".
As I stated above it may be that the return value is
correct - in which case the documentation should be
updated to let developers know that this is not a valid
value.
This bug can be reproduced always.
---------- BEGIN SOURCE ----------
import java.math.BigInteger;
public class ProbablePrimeBug
{
public static void main(final String[] argv)
{
final BigInteger num = new BigInteger("4");
System.out.println(num.isProbablePrime(1000));
System.out.println(num.isProbablePrime(Integer.MAX_VALUE));
System.out.println(num.isProbablePrime(Integer.MAX_VALUE - 1));
}
}
---------- END SOURCE ----------
CUSTOMER WORKAROUND :
Integer.MAX_VALUE - 1.
(Review ID: 144255)
======================================================================
- duplicates
-
JDK-4655458 BigInteger.isProbablePrime(Integer.MAX_VALUE) returns true for even numbers
-
- Closed
-