RFR: JDK-8326908: DecimalFormat::toPattern throws OutOfMemoryError when pattern is empty string

Raju Gupta duke at openjdk.org
Mon Mar 4 21:42:52 UTC 2024


On Sat, 2 Mar 2024 00:34:32 GMT, Justin Lu <jlu at openjdk.org> wrote:

> Please review this PR and corresponding CSR which prevents an OutOfMemoryError by restricting the initial maximum fraction digits for an empty pattern DecimalFormat.
> 
> For an empty String pattern DecimalFormat, the maximum fraction digits is initialized to `Integer.MAX_VALUE`. When toPattern() is invoked, StringBuilder internally doubles capacity attempting to append Integer.MAX_VALUE digits until OOME occurs. CSR covers potential behavioral compatibility changes.

Would declaring an object for the input and then invoking the two methods on the same object rather than creating two objects be considered an alternative?

-------------

Marked as reviewed by rajucomp at github.com (no known OpenJDK username).

PR Review: https://git.openjdk.org/jdk/pull/18094#pullrequestreview-1915406613


More information about the core-libs-dev mailing list