<i18n dev> RFR: 8276220: Reduce excessive allocations in DateTimeFormatter [v3]

Claes Redestad redestad at openjdk.java.net
Wed Nov 3 13:14:43 UTC 2021

On Wed, 3 Nov 2021 12:44:39 GMT, Claes Redestad <redestad at openjdk.org> wrote:

>> I'll see to it.
> When adding a test for this I discovered that  `FractionPrinterParser::format` will end up calling `field.range().checkValidValue(value, field)` [here](https://github.com/openjdk/jdk/blob/579b2c017f24f2266abefd35c2b8f28fa7268d93/src/java.base/share/classes/java/time/format/DateTimeFormatterBuilder.java#L3543). This means that the pre-existing implementation does check the value range and throws exceptions when trying to print a `value` outside of the `field` range. 
> To mimic the existing behavior we have to do the same check in `NanosPrinterParser::format` and drop the fallback (which would have somewhat nonsensical output for values outside the range, anyhow).

Added a test case showing that values that are outside the range throw `DateTimeException`. This passes with and without the patch and mainly documents the pre-existing behavior.


PR: https://git.openjdk.java.net/jdk/pull/6188

More information about the i18n-dev mailing list