Propose to make j.t.f.DateTimePrintContext immutable

Chen Liang chen.l.liang at oracle.com
Fri Sep 19 05:48:24 UTC 2025


Hi wenshao,
I think this is a very good proposal that makes code much cleaner. This allows us to migrate this context to value classes in the future for better optimization, improves the thread safety of the optional status tracking (compared to throwing exceptions), and makes the context thread safe.

Regards,
Chen
________________________________
From: core-libs-dev <core-libs-dev-retn at openjdk.org> on behalf of wenshao <shaojin.wensj at alibaba-inc.com>
Sent: Thursday, September 18, 2025 8:16 PM
To: core-libs-dev <core-libs-dev at openjdk.org>
Subject: Propose to make j.t.f.DateTimePrintContext immutable

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.

In order to make it easier for reviewers to see my ideas, I submitted a draft Pull Request ( https://github.com/openjdk/jdk/pull/26913 ). Please give me feedback.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mail.openjdk.org/pipermail/core-libs-dev/attachments/20250919/c3084302/attachment-0001.htm>


More information about the core-libs-dev mailing list