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

BigInteger doesn't fail on invalid number format (-00-00).

    XMLWordPrintable

Details

    • b51
    • x86
    • windows_2000

    Description



      Name: rmT116609 Date: 04/27/2004


      FULL PRODUCT VERSION :
      java version "1.4.2_04"
      Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.2_04-b05)
      Java HotSpot(TM) Client VM (build 1.4.2_04-b05, mixed mode)

      java version "1.5.0-beta"
      Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0-beta-b32c)
      Java HotSpot(TM) Client VM (build 1.5.0-beta-b32c, mixed mode)


      ADDITIONAL OS VERSION INFORMATION :
      Microsoft Windows 2000 [Version 5.00.2195]

      A DESCRIPTION OF THE PROBLEM :
      If the String passed to the BigInteger(String) constructor is "-00(multiple
      0's...)00-00(multiple 0's)00" then the BigInteger object is created even though such a String is badly formatted. When System.out.println (BigInteger) is used for such numbers it throws ArrayIndexOutOfBoundsException.

      Normally for these kinds of numbers NumberFormatException should be thrown when the object is created.

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      Run the TestCode provided below.
      You can give any String with these formats:
      " - (one or more 0's) - (one or more 0's) "

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      Should throw an NumberFormatException if such numbers are passed to the BigInteger constructors.
      ACTUAL -
      1. No Exception when such numbers are passed to the BigInteger constructor.
      2. When such numbers are printed with System.out.println() follwing exception is thrown.
      Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: -1
              at java.math.BigInteger.toString(BigInteger.java:2642)
              at java.math.BigInteger.toString(BigInteger.java:2677)
              at java.lang.String.valueOf(String.java:2498)
              at java.io.PrintStream.print(PrintStream.java:558)
              at java.io.PrintStream.println(PrintStream.java:695)
              at TwoSignTest.main(TwoSignTest.java:9)

      ERROR MESSAGES/STACK TRACES THAT OCCUR :
      Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: -1
              at java.math.BigInteger.toString(BigInteger.java:2642)
              at java.math.BigInteger.toString(BigInteger.java:2677)
              at java.lang.String.valueOf(String.java:2498)
              at java.io.PrintStream.print(PrintStream.java:558)
              at java.io.PrintStream.println(PrintStream.java:695)
              at TwoSignTest.main(TwoSignTest.java:9)

      REPRODUCIBILITY :
      This bug can be reproduced always.

      ---------- BEGIN SOURCE ----------
      import java.math.*;
        public class TwoSignTest
        {
          public static void main(String args[])
          {
            BigInteger b1 = new BigInteger("-000-0");
            // ArrayIndexOutOfBoundsException if System.out.println() used or
           // else no problem.
            System.out.println(b1);
          }
        }
      ---------- END SOURCE ----------

      CUSTOMER SUBMITTED WORKAROUND :
      Check the format before passing it to BigInteger constructor.
      (Incident Review ID: 259950)
      ======================================================================

      Attachments

        Issue Links

          Activity

            People

              darcy Joe Darcy
              rmandalasunw Ranjith Mandala (Inactive)
              Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved:
                Imported:
                Indexed: