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: Resolved
  • Resolution: Fixed
  • Submitted: 2024-06-21
  • Updated: 2025-06-11
  • Resolved: 2025-05-28
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.
JDK 25
25 b26Fixed
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
Changeset: 4ced4e73 Branch: master Author: gauthamkrishnanibm <gautham.k@ibm.com> Committer: Roger Riggs <rriggs@openjdk.org> Date: 2025-05-28 15:38:00 +0000 URL: https://git.openjdk.org/jdk/commit/4ced4e73fc0a517df826860839681004bb67e624
28-05-2025

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