JDK-6372822 : REGRESSION: DecimalFormat.toPattern() causes OutOfMemoryError
  • Type: Bug
  • Component: core-libs
  • Sub-Component: java.text
  • Affected Version: 5.0
  • Priority: P3
  • Status: Closed
  • Resolution: Not an Issue
  • OS: windows_xp
  • CPU: x86
  • Submitted: 2006-01-16
  • Updated: 2019-10-08
  • Resolved: 2006-01-17
Related Reports
Duplicate :  
Relates :  
Relates :  
Description
FULL PRODUCT VERSION :
JDK 1.5 update 6

ADDITIONAL OS VERSION INFORMATION :
Happens in Windows XP and Linux. This isn't an OS specific problem.

A DESCRIPTION OF THE PROBLEM :
DecimalFormat with empty string causes OutOfMemoryError: Java heap space in toPattern method.

STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      DecimalFormat df = new DecimalFormat("");
      System.out.println(df.toPattern());

Under JDK 1.4.2, this returns:

#,###.##########################################################################
################################################################################
################################################################################
################################################################################
##########################

Under JDK 1.5 06, this causes the following exception:

Exception in thread "main" java.lang.OutOfMemoryError: Java heap space

EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
#,###.##########################################################################
################################################################################
################################################################################
################################################################################
##########################

ACTUAL -
Exception in thread "main" java.lang.OutOfMemoryError: Java heap space

ERROR MESSAGES/STACK TRACES THAT OCCUR :
Exception in thread "main" java.lang.OutOfMemoryError: Java heap space

REPRODUCIBILITY :
This bug can be reproduced always.

---------- BEGIN SOURCE ----------
import java.text.DecimalFormat;
public class TestDecimalFormat {
  public static void main(String[] args) {
    DecimalFormat df = new DecimalFormat("");
    System.out.println(df.toPattern());
  }
}

---------- END SOURCE ----------

Release Regression From : 1.4.2_10
The above release value was the last known release where this 
bug was known to work. Since then there has been a regression.

Comments
EVALUATION This is not a regression but is nevertheless a result of the fix for 4018937. The instance of Decimalformat("") works as expected for parsing or formatting. Because its maximum integer digits and maximum fraction digits are Integer.MAX_VALUE, toPattern() throws OEM. But it doesn't seem to be a critical issue.
17-01-2006