OpenJDK Quality Group Requests Testing for Value Classes in JDK 28
The OpenJDK Quality Group is calling for developers to test their projects against JDK 28 as the introduction of value classes through JEP 401 brings significant changes to object identity and synchronization.
The OpenJDK Quality Group asks open-source projects to test code against JDK 28 with preview features on and off. JEP 401 introduces value classes as a preview feature in JDK 28. This change has unusual compatibility consequences.
With previews enabled, 30 JDK classes become value classes. This list includes primitive wrappers like Integer, Long, Double, and Boolean, plus Number and Record. Optional, OptionalInt, OptionalLong, and OptionalDouble are covered. In java.time, the classes are LocalDate, LocalTime, LocalDateTime, ZonedDateTime, Instant, Duration, Period, Year, YearMonth, and MonthDay. Chrono classes MinguoDate, HijrahDate, JapaneseDate, and ThaiBuddhistDate are included.
Existing code changes behavior without edits, even when compiled without preview features or on older releases. Value classes lack identity. The == operator compares value objects by field values. Synchronizing on value objects or calling wait and notify throws an IdentityException or causes a compile error. The java.lang.ref APIs and WeakHashMap throw an IdentityException with value objects. Calling setAccessible on their fields causes an IllegalAccessException.
Compiling with preview features on in JDK 28 subjects existing record constructors to extra rules from JEP 513, which finalized flexible constructor bodies. Constructor code runs in an early construction phase by default, limiting interactions with this to field assignments. Calling an instance method causes a compile error.
Report unexpected JDK misbehavior to the valhalla-dev mailing list.
