JDK-8334742 : Change java.time month/day field types to 'byte'
  • Type: Bug
  • Component: core-libs
  • Sub-Component: java.time
  • Affected Version: 23
  • Priority: P4
  • Status: In Progress
  • Resolution: Unresolved
  • Submitted: 2024-06-21
  • Updated: 2025-04-30
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
Other
tbdUnresolved
Related Reports
Relates :  
Description
In the following classes, month and day values are stored in fields of type 'int' or 'short'. The range of allowed values is small enough that the type can be 'byte' instead.

java.time.YearMonth
java.time.MonthDay
java.time.LocalDate
java.time.chono.HijrahDate

Refactoring the type will give the JVM a little more layout flexibility, and will be especially useful when these classes become value classes. (For example, it reduces YearMonth and MonthDay to a payload size smaller than 64 bits, which can be significant.)

Generally, field type changes are disruptive to serialization, but these classes use a custom Externalizable encoding (see 'readExternal'/'writeExternal') which already stores these values as bytes.
Comments
A pull request was submitted for review. Branch: master URL: https://git.openjdk.org/jdk/pull/24975 Date: 2025-04-30 20:30:59 +0000
30-04-2025

I've confirmed with the original author that there was no strong motivation to use types larger than 'byte', just a vague sense that a payload of exactly 64 bits might be important somehow.
21-06-2024