JDK-8230114 : DecimalFormat.toLocalizedPattern() can cause OOME
  • Type: Bug
  • Component: core-libs
  • Sub-Component: java.text
  • Priority: P3
  • Status: Resolved
  • Resolution: Duplicate
  • Submitted: 2019-08-23
  • Updated: 2019-10-08
  • Resolved: 2019-10-08
Related Reports
Duplicate :  
Relates :  
Description
The somewhat nonsensical snippet of code

    new DecimalFormat("").toLocalizedPattern()

will allocate memory continuously until OutOfMemoryError is thrown.

It seems like the empty string is an invalid pattern, so it should throw IAE.
Comments
Closing this as a duplicate of JDK-6372822, as the reason mentioned above.
08-10-2019

There were similar issues filed in the past (as in JDK-6372822), which were closed as WNF. The reason was that the formatter's max integer/fraction numbers are Integer.MAX_VALUE thus to(Localized)Pattern() consumes the memory till "#" is appended for that max value. Although an empty string is not allowed in the ABNF in the class description, there seem to be usages of DecimalFormat("") in the real applications, so simply changing it to throw an IAE would break those applications.
08-10-2019