ICU4J: setDecimalPatternMatchRequired requires decimal even if field parses to INF/NaN

Description

If `setDecimalPatternMatchRequired(true)` is called on a `DecimalFormat` and the pattern contains a decimal separator, but the data to parse contains an infinity or NaN representation, then `parse()` returns and error instead of returning Double infinity/NaN.

Code to reproduce the issue:

```scala
DecimalFormatSymbols symbols = DecimalFormatSymbols.getInstance(java.util.Locale.US);
symbols.setInfinity("INF")

DecimalFormat df = new DecimalFormat("0.00", symbols)
df.setDecimalPatternMatchRequired(true)

Number res = df.parse("INF", new ParsePosition(0))
assertEquals(Double.POSITIVE_INFINITY, res)
```

Note that Inf/NaN works as expected if the pattern does not contain a decimal separator since the data also won't contain a decimal separator.

The issue seems to be in the `RequireDecimalSeparatorValidator`:

https://github.com/unicode-org/icu/blob/main/icu4j/main/classes/core/src/com/ibm/icu/impl/number/parse/RequireDecimalSeparatorValidator.java#L26-L29

It seems there might want to be an exception so this validator always succeeds if FLAG_NAN or FLAG_INFINITY is set, so that a decimal is only required if it actually parsed a number?

Activity

Show:

Rich Gillam 
March 19, 2025 at 11:20 PM

Really sorry about the long delay here. Thanks for prodding us to finally get this in!

Steve Lawrence 
March 19, 2025 at 12:26 PM

Is there anything I can do to help get this merged? This issue has a PR with a fix to Java and C versions, with tests and approvals:

Markus Scherer 
April 20, 2023 at 4:14 PM

Thanks! We will take a look!

Steve Lawrence 
April 13, 2023 at 11:14 PM

PR created here:

Steve Lawrence 
April 13, 2023 at 5:48 PM

I can give it a shot

Fixed by Other Ticket

Details

Assignee

Reporter

Components

Reviewer

Priority

Time Needed

Hours

Fix versions

Created March 6, 2023 at 9:19 PM
Updated March 19, 2025 at 11:20 PM
Resolved March 19, 2025 at 11:20 PM