On Thu, 2 Oct 2025 03:08:32 GMT, Shaojin Wen <[email protected]> wrote:

>> I propose to make j.t.f.DateTimePrintContext immutable.
>> 
>> Currently, DateTimePrintContext has only one mutable field, optional. This 
>> can be replaced by adding an optional parameter to the 
>> DateTimeFormatter.formatTo method.
>> 
>> Immutable DateTimePrintContext can be optimized by escape analysis, such as 
>> immutable object optimization.
>
> Shaojin Wen has updated the pull request incrementally with one additional 
> commit since the last revision:
> 
>   Improve javadoc for optional parameter in DateTimePrinterParser#format 
> method

And one more thought/question:
The optionality of formatting is a parameter used in the traversal of the 
formatting and parsing and affect nested formatting calls.  The 
DateTimePrintContext previously counts the depth of the nesting with >0 
indicating optional.
It is the component that determines (based on optional:true) whether an absent 
value throws.
Was it considered to change DateTimePrinterContext.optional to `final boolean 
optional` and create a second instance with optional=true. 

Only the CompositePrinterParser changes the state to indicate that nested 
PrinterParsers are optional.
CompositePrinterParser could substitute the optional DateTimePrintContext.
That would be closer to the current design and if allow it to be immutable.

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

PR Comment: https://git.openjdk.org/jdk/pull/26913#issuecomment-3361215508

Reply via email to