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