JDK-4259453 : java.math.BigDecimal("1.2e") throws StringIndexOutOfBoundsException
  • Type: Bug
  • Component: core-libs
  • Sub-Component: java.lang
  • Affected Version: 1.3.0
  • Priority: P3
  • Status: Closed
  • Resolution: Fixed
  • OS: solaris_2.5.1
  • CPU: sparc
  • Submitted: 1999-08-04
  • Updated: 1999-10-26
  • Resolved: 1999-09-04
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
1.3.0 kestrelFixed
Related Reports
Relates :  
Relates :  
Description

Name: sdC67446			Date: 08/04/99


The constructor
public BigDecimal(String val)
of class java.math.BigDecimal throws StringIndexOutOfBoundsException
if 'val' represents the number with no exponent after 'e'-symbol.
NumberFormatException expected.

The doc says:
-------------------------------------------------------------
public BigDecimal(String val)

     Translates the String representation of a BigDecmal into a
     BigDecimal. The String representation consists of an optional
     sign ('+' or '-') followed by a sequence of zero or more decimal
     digits ("the integer"), optionally followed by a fraction,
     optionally followed by an exponent.  

     The fraction consists of of a decimal point followed by zero or
     more decimal digits. The string must contain at least one digit
     in either the integer or the fraction. The number formed by the
     sign, the integer and the fraction is referred to as the
     significand.  

     The exponent consists of the character 'e'(0x75) or E (0x45)
     followed by one or more decimal digits. The value of the
     exponenet must lie between Integer.MIN_VALUE and
     Integer.MAX_VALUE, inclusive.  

     The scale of the returned BigDecimal will be the number of digits
     in the fraction, or zero if the string contains no decimal point,
     subject to adjustment for any exponent: If the string contains an
     exponent, the exponent is subtracted from the scale. If the
     resulting scale is negative, the scale of the returned BigDecimal
     is zero and the unscaled value is multiplied by the appropriate
     power of ten so that, in every case, the resulting BigDecimal is
     equal to significand * 10exponent.  

     The character-to-digit mapping is provided by
     Character.digit(char, int). The String may not contain any
     extraneous characters (whitespace, for example).  

     Note: For floats (and doubles) other that NAN, +INFINITY and
     -INFINITY, this constructor is compatible with the values
     returned by Float.toString (and Double.toString). This is
     generally the preferred way to convert a float (or double) into a
     BigDecimal, as it doesn't suffer from the unpredictability of the
     BigDecimal(double) constructor.  

     Note: the optional leading plus sign and trailing exponent were
     added in release 1.3. 
     Parameters:
         val - String representation of BigDecimal.
     Throws:
         NumberFormatException - val is not a valid representation of
         a BigDecimal. 
------------------------------------------------------------
The test demonstrating the bug:
-------------------------------------------------------------
import java.math.BigDecimal;

public class Test {
    public static void main(String[] args) {
	try {
            BigDecimal bd = new BigDecimal("1.2e");
	} catch (Exception e) {
            e.printStackTrace();
	}
    }
}

Output for Classic VM (build JDK-1.3-L, green threads, nojit)
-------------------------------------------------------------
Warning: JIT compiler "sunwjit" not found. Will use interpreter.
java.lang.StringIndexOutOfBoundsException: String index out of range: 0
        at java.lang.String.charAt(String.java:506)
        at java.math.BigDecimal.<init>(BigDecimal.java:144)
        at Test.main(Test.java:6)
-------------------------------------------------------------
======================================================================

Comments
CONVERTED DATA BugTraq+ Release Management Values COMMIT TO FIX: kestrel FIXED IN: kestrel INTEGRATED IN: kestrel VERIFIED IN: kestrel
14-06-2004

EVALUATION Yep. This will be fixed. michael.mccloskey@eng 1999-09-01
01-09-1999