On Wed, 3 Nov 2021 12:21:00 GMT, Claes Redestad <redes...@openjdk.org> wrote:

>> src/java.base/share/classes/java/time/format/DateTimeFormatterBuilder.java 
>> line 3266:
>> 
>>> 3264:             if (!field.range().isValidIntValue(value)) {
>>> 3265:                 if (fallback == null) {
>>> 3266:                     fallback = new FractionPrinterParser(field, 
>>> minWidth, maxWidth, decimalPoint, subsequentWidth);
>> 
>> It would be nice to see a test case cover this.
>
> 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).

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

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

Reply via email to