JDK-4489146 : BigInteger(String, int) does not fail on multiple minus signs
  • Type: Bug
  • Component: core-libs
  • Sub-Component: java.math
  • Affected Version: 1.3.1_07,1.4.0
  • Priority: P4
  • Status: Resolved
  • Resolution: Fixed
  • OS: generic
  • CPU: generic
  • Submitted: 2001-08-07
  • Updated: 2003-06-14
  • Resolved: 2001-09-14
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
Other Other Other Other
1.2.2_016 016Fixed 1.2.2_16Fixed 1.3.1_09Fixed 1.4.0Fixed
Related Reports
Duplicate :  
Relates :  
Description

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

Comments
CONVERTED DATA BugTraq+ Release Management Values COMMIT TO FIX: 1.2.2_016 1.2.2_16 1.3.1_09 merlin-beta3 FIXED IN: 1.2.2_016 1.2.2_16 1.3.1_09 merlin-beta3 INTEGRATED IN: 1.2.2_016 1.2.2_16 1.3.1_09 merlin-beta3 VERIFIED IN: 1.3.1_09 merlin-beta3 merlin-rc1
14-06-2004

WORK AROUND Name: yyT116575 Date: 08/07/2001 // We have to do the following to ensure that 'num' contains a valid // BigInteger/BigDecimal, or that the BigInteger/BigDecimal constructor // throws a NumberFormatException. if (num.startsWith("+") && !num.startsWith("+-")) { num= num.substring(1); } else if (num.startsWith("-") && num.substring(1).indexOf("-") > -1) { throw new NumberFormatException("Illegal embedded minus sign"); } // Now, do whatever you want with num. ======================================================================
11-06-2004

EVALUATION Yes, this is a a valid bug. joe.darcy@eng 2001-08-07
07-08-2001