JDK-4488017 : java.math.BigDecimal("+") throws StringIndexOutOfBoundsException
  • Type: Bug
  • Component: core-libs
  • Sub-Component: java.math
  • Affected Version: 1.3.0,1.4.0
  • Priority: P3
  • Status: Closed
  • Resolution: Fixed
  • OS: generic,solaris_2.5.1
  • CPU: generic,x86
  • Submitted: 2001-08-03
  • Updated: 2001-10-19
  • 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
1.4.0 beta3Fixed
Related Reports
Duplicate :  
Relates :  
Relates :  
Relates :  
Relates :  
Relates :  
Description

Name: bsC130419			Date: 08/03/2001


The constructor
 public BigDecimal(String val)
of class java.math.BigDecimal throws StringIndexOutOfBoundsException
if 'val' is the string "+".
NumberFormatException expected.
(JDK1.2's BigDecimal throws NumberFormatException.)

Following is a test code.
--------------------------------------------
import java.math.BigDecimal;

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

Following is a output of the test code.

------------------------------------------------
% java -version
java version "1.3.0_01"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.3.0_01)
Java HotSpot(TM) Client VM (build 1.3.0_01, mixed mode)

% java BigDecimalTest
java.lang.StringIndexOutOfBoundsException: String index out of range: 0
        at java.lang.String.charAt(String.java:507)
        at java.math.BigDecimal.<init>(BigDecimal.java:131)
        at BigDecimalTest.main(BigDecimalTest.java:6)
-------------------------------------------------
(Review ID: 120709) 
======================================================================

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

WORK AROUND Name: bsC130419 Date: 08/03/2001 I temporarily changed my code to catch Exception instead of NumberFormatException. ======================================================================
11-06-2004

EVALUATION Confirmed reported behavior. This is a relatively minor variant from the spec. joe.darcy@eng 2001-08-05 Putting in additional tests to detect invalid "+" and "e+" strings. As these checks only happen once per string, they should (hopefully) not affect the speed improvements made in 4294519. joe.darcy@eng 2001-08-06
06-08-2001