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

BigInteger(String, int) does not fail on multiple minus signs

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: P4 P4
    • 1.2.2_016
    • 1.3.1_07, 1.4.0
    • core-libs
    • 016
    • generic
    • generic



        Name: yyT116575 Date: 08/07/2001


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

        If the String passed to the BigInteger(String, int) constructor begins with "--
        " (two minus signs), or "-0-" then a BigInteger object is created even though
        such a String is badly formatted. Since BigDecimal(String) depends on the
        above BigInteger constructor, BigDecimal also has this problem.


        Example:

        import java.math.BigInteger;

        public class BigIntegerTest {
          static BigInteger bi;

          public static void main(String[] args) {
            bi = new BigInteger("--1234567890");
            System.out.println("--123456790 => " + bi);

            bi = new BigInteger("-0-12345678");
            System.out.println("-0-12345678 => " + bi);
          }
        }

        I get the following output:
             --1234567890 => -4294967295234567890
             -0-12345678 => -4282621618

        In fact, I've done some experimenting and I've only been able to get the
        NumberFormatException to occur when there are no non-zero digits after the
        second minus sign, or when radix is 10 and the number of non-zero digits
        after the second minus sign is 9.
        (Review ID: 129484)
        ======================================================================

              darcy Joe Darcy
              yyoungsunw Yung-ching Young (Inactive)
              Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

                Created:
                Updated:
                Resolved:
                Imported:
                Indexed: