Name: jl125535 Date: 03/20/2002
FULL PRODUCT VERSION :
F:\>java -version
java version "1.3.1"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.3.1-b24)
Java HotSpot(TM) Client VM (build 1.3.1-b24, mixed mode)
FULL OPERATING SYSTEM VERSION : win2k pro
Verified on Solaris 8 with both JDK 1.3.1 and JDK 1.4.
A DESCRIPTION OF THE PROBLEM :
java.math.BigInteger.isProbablePrime(Integer.MAX_VALUE) returns true for even numbers from 4 to 1*10^6 (and probably beyond).
Note that BigInteger.isProbablePrime(Integer.MAX_VALUE - 1) correctly returns false for those same values.
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
run the test case
This bug can be reproduced always.
---------- BEGIN SOURCE ----------
import java.math.BigInteger;
public class Test
{
public static void main(String[] args)
{
BigInteger onemill = new BigInteger(1000000 + "");
BigInteger two = new BigInteger(2 + "");
BigInteger test = new BigInteger(0 + "");
while (true)
{
if (test.isProbablePrime(Integer.MAX_VALUE))
{
// This line should never appear (except for 2)
//System.out.println(test
// + ".isProbablePrime(MAX_VALUE) = false");
}
else
{
// This line should always appear (exepct for 2)
//this will only be printed if sProbablePrime is correct
//except test value of 2
System.out.println(test
+ ".isProbablePrime(MAX_VALUE) = false");
}
test = test.add(two);
if (test.equals(onemill))
{
System.out.println("If only this line appeared, the test "
+ "failed.");
break;
}
}
}
}
---------- END SOURCE ----------
CUSTOMER WORKAROUND :
don't use Integer.MAX_VALUE for the certainty
(Review ID: 144259)
======================================================================
- duplicates
-
JDK-4654323 BigInteger isProbablPrime does not work for Integer.MAX_VALUE
-
- Closed
-