On Sat, 2 Mar 2024 00:34:32 GMT, Justin Lu <j...@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.
src/java.base/share/classes/java/text/DecimalFormat.java line 3717: > 3715: // As maxFracDigits are fully displayed unlike maxIntDigits > 3716: // Prevent OOME by setting to a much more reasonable value. > 3717: setMaximumFractionDigits(DOUBLE_FRACTION_DIGITS); Setting a reasonable default makes sense. In other control paths, the max fraction digits come from the inputs or are explicitly set. It might be a reasonable related change to use StringBuilder.repeat() instead of a loop at LIne 3312-3319, where the pattern char(s) are being appended to the result. ------------- PR Review Comment: https://git.openjdk.org/jdk/pull/18094#discussion_r1511404338