Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-4654323

BigInteger isProbablPrime does not work for Integer.MAX_VALUE

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: P4 P4
    • 1.4.1
    • 1.4.0
    • core-libs
    • hopper
    • x86
    • windows_2000, windows_xp
    • Verified



      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)
      ======================================================================

            darcy Joe Darcy
            gmanwanisunw Girish Manwani (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: