RFR: 6177299: [Fmt-Nu] NumberFormat.getPercentInstance() does not work correctly

Justin Lu jlu at openjdk.org
Mon Sep 29 21:46:18 UTC 2025


Please review this PR which corrects an edge case bug for `DecimalFormat` parsing when a multiplier is applied.

This issue applies to any parsed Strings whose resultant double value is rounded to _9.223372036854776E18_ after the multiplier is applied. The returned value is incorrectly given as `Long.MAX_VALUE` when it should be returned as the double _9.223372036854776E18_.

For example, the String _"922,337,203,685,477,600,000%"_ is first parsed as _9.223372036854776E20_, after which the multiplier is then applied to give _9.223372036854776E18_. The original code evaluates `9.223372036854776E18 == (double)(long)9.223372036854776E18` as true, leading to the long representation returned.

The double value should first be checked if it is within the long min/max range before being checked if it can be represented as a long. Note that the check should be inclusive, as during the comparison, `Long.MAX_VALUE` is promoted to _9.223372036854776E18_. Thus _9.223372036854775E18_ correctly compares as false, and all doubles above compare as true.

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

Commit messages:
 - init

Changes: https://git.openjdk.org/jdk/pull/27563/files
  Webrev: https://webrevs.openjdk.org/?repo=jdk&pr=27563&range=00
  Issue: https://bugs.openjdk.org/browse/JDK-6177299
  Stats: 30 lines in 2 files changed: 25 ins; 0 del; 5 mod
  Patch: https://git.openjdk.org/jdk/pull/27563.diff
  Fetch: git fetch https://git.openjdk.org/jdk.git pull/27563/head:pull/27563

PR: https://git.openjdk.org/jdk/pull/27563


More information about the core-libs-dev mailing list