On Mon, 3 Jun 2024 22:32:54 GMT, Justin Lu <j...@openjdk.org> wrote: > Please review this PR which handles incorrect CompactNumberFormat integer > only parsing when there is no suffix. > > See the following snippet, > > > var fmt = NumberFormat.getCompactNumberInstance(Locale.US, > NumberFormat.Style.SHORT) > fmt.setParseIntegerOnly(true) > fmt.parse("5K") // returns 5000 > fmt.parse("50.00") // returns 50 > fmt.parse("5") // unexpectedly throws StringIndexOutOfBoundsException > fmt.parse("5 ") // returns 5 > > > Within the `parse` method, there is code that advances `position` past the > fractional portion to find the suffix when `parseIntegerOnly()` is true. > However, if a valid string input is given with no suffix, > `DecimalFormat.subparseNumber()` will fully iterate through the string and > `position` will be equal to the length of the string, throwing > StringIndexOutOfBoundsException when `charAt` is invoked (line 1740). > > We should check to make sure position does not exceed the string length > before deciding to check for a decimal symbol.
This pull request has now been integrated. Changeset: 6238bc8d Author: Justin Lu <j...@openjdk.org> URL: https://git.openjdk.org/jdk/commit/6238bc8da2abe7a1f0cdd98c0af01e9ba1869ec3 Stats: 26 lines in 2 files changed: 24 ins; 0 del; 2 mod 8333456: CompactNumberFormat integer parsing fails when string has no suffix Reviewed-by: naoto ------------- PR: https://git.openjdk.org/jdk/pull/19533