Java 29 LTS and Value Objects: The Identity Bugs No Flag Catches
Java 29 will not be the LTS that turns value types on. Value objects land in JDK 28 as a preview and will very likely still be one when the Java 29 LTS ships. I ran one small identity audit on JDK 21 and on the JDK 28 early-access build: with the preview on, all four answers changed, and two of them changed with no warning from javac or any JVM flag. Here is what breaks, what the tooling catches, and the CI job I would add now.
The Java 29 LTS is due in September 2027, and much of the talk about it assumes it will be the release that finally gives Java value types. It probably won't. Value objects (JEP 401) arrive in JDK 28 as a preview, and Brian Goetz has called hoping they leave preview in time for Java 29 "optimistic". So for a shop that only runs LTS releases, Java 29 ships value objects behind --enable-preview. The useful work is not adopting them. It is finding the code that depends on object identity, because two of the five identity hazards I tested are invisible to every compiler warning and JVM flag until you actually run with the preview turned on.
I ran the same four identity checks on JDK 21 and on the JDK 28 early-access build. With the preview off, both print the same answers. With the preview on, JDK 28 changes all four, and nothing warned me about two of them.
Why the Java 29 LTS still ships value objects in preview
The release train is fixed. JDK 28 ships in March 2027 and Java 29 in September 2027 (The Register, June 2026). JEP 401 was targeted to JDK 28 in late July (InfoQ, July 27 roundup), and JDK 28's feature set freezes in early December, which is this week (InfoQ on JDK 27 GA). A first preview in March leaves one release before the LTS. For scale, structured concurrency previewed in every release from JDK 21 to JDK 27 before JEP 543 targeted it as final for JDK 28. Goetz also warned against expecting the preview window to be shorter than usual.
Two more pieces of Project Valhalla are not in JDK 28 at all. Null-restricted value class types, the part that would let the JVM drop the null flag and flatten larger values, is still a draft JEP (JEP draft 8316779). So the Java 29 you will deploy has value classes you can opt into, a list of JDK classes that turn into value classes when you do, and the same runtime as before when you don't.
That last part is the trap. "Opt-in" sounds like "no risk", and for your own classes it is. But the opt-in also changes Integer, Long, Optional, LocalDate, Instant, Duration and about a dozen java.time classes in all (JEP 401). You don't decide whether your code uses those classes. Your dependencies already do.
What JEP 401 says stops working
The JEP removes identity from value objects, and every operation that needs identity has to fail or change meaning. From the JEP text:
==on two value objects compares their fields, not their addresses.synchronizedon a value object throwsIdentityException, and is a compile-time error when the static type is a value class.waitandnotifythrowIllegalMonitorStateException.- Creating a
Referenceto a value object throwsIdentityException, which takesWeakReference,SoftReferenceand everything built on them with it. - Non-record value classes that implement
SerializableneedwriteReplaceandreadResolve.
None of this is new as an intention. The Javadoc has called these classes value-based for years and told you not to rely on their identity, and since JDK 16 (JEP 390) javac and the JVM have been able to warn about it. What changes in JDK 28 is that the warning becomes behavior.
Four identity checks, run on JDK 21 and JDK 28
I wanted to see the difference rather than read about it, so I wrote one file that compiles on any JDK from 21 up and only uses ordinary APIs. Each check runs inside a small harness that prints either the result or the name of the exception.
import java.lang.ref.WeakReference;
import java.time.LocalDate;
import java.util.IdentityHashMap;
import java.util.Map;
public class IdentityAudit {
interface Probe {
String run() throws Exception;
}
static void check(String name, Probe probe) {
String result;
try {
result = probe.run();
} catch (Throwable t) {
result = t.getClass().getSimpleName();
}
System.out.printf("%-26s %s%n", name, result);
}
public static void main(String[] args) {
System.out.println("java " + Runtime.version());
Integer a = Integer.valueOf(1000);
Integer b = Integer.valueOf(1000);
LocalDate day = LocalDate.of(2027, 9, 14);
check("Integer 1000 == 1000", () -> String.valueOf(a == b));
check("synchronized (Integer)", () -> {
synchronized ((Object) a) {
return "locked";
}
});
check("WeakReference(LocalDate)", () ->
new WeakReference<Object>(day).get() + " held");
check("IdentityHashMap size", () -> {
Map<Object, String> seen = new IdentityHashMap<>();
seen.put(a, "first");
seen.put(b, "second");
return String.valueOf(seen.size());
});
}
}Run it with the source launcher on your current JDK, then on a JDK 28 build with the preview enabled:
java IdentityAudit.java
java --enable-preview IdentityAudit.javaTwo lines are doing more than they look. 1000 is outside the Integer cache, which only covers -128 to 127, so valueOf returns two separate boxes and == is false on every JDK you run in production today. And the (Object) cast in the synchronized block is deliberate: it is what real code looks like when the lock arrives as a generic T or an Object key from a map, and it hides the type from the compiler.
On OpenJDK 21.0.13.1 and on JDK 28 build 28-ea+26 without the preview, the output is identical:
Integer 1000 == 1000 false
synchronized (Integer) locked
WeakReference(LocalDate) 2027-09-14 held
IdentityHashMap size 2With --enable-preview on the same JDK 28 build, every line changes:
Integer 1000 == 1000 true
synchronized (Integer) IdentityException
WeakReference(LocalDate) IdentityException
IdentityHashMap size 1The two exceptions are loud, and the messages are clear. Synchronizing reports "Cannot synchronize on an instance of value class java.lang.Integer", and a separate test that put a LocalDate key into a WeakHashMap reported "java.time.LocalDate is not an identity class". The other two lines are quiet. A comparison that used to be false is now true, and a map that used to hold two entries now holds one. Nothing throws. The program just computes a different answer.
Which tools catch the identity bugs before the preview does
Then I checked what each tool reports before I flip the switch. Three tools are available: the compiler lint, a diagnostic JVM flag, and the preview itself. I also ran a second file with the lock typed as Integer and a WeakHashMap<LocalDate, String> cache, because those are the two shapes I would expect in a real service.
| Identity hazard | JDK 21 tooling | JDK 28 lint | JDK 28 preview |
|---|---|---|---|
synchronized on a typed Integer | javac warning | warning | compile error |
synchronized through Object | JVM flag only | silent | IdentityException |
WeakHashMap with LocalDate keys | silent | warning | IdentityException |
== on two boxed values | silent | silent | answer flips |
IdentityHashMap of boxed values | silent | silent | fewer entries |
The JDK 21 column comes from two places. javac's synchronization lint is on by default and caught the typed lock without any flag. The JVM flag catches what the compiler can't see: with -XX:+UnlockDiagnosticVMOptions -XX:DiagnoseSyncOnValueBasedClasses=2, JDK 21 logged "Synchronizing on object ... of klass java.lang.Integer" with a stack trace pointing at the cast line. Setting it to 1 instead turns that into a fatal VM error, which is useful for one CI job and dangerous anywhere else.
The JDK 28 column shows the compiler getting better. The lint key is now called identity, and synchronization is kept as a deprecated alias. Under -Xlint:identity, JDK 28 warns on the WeakReference and on every WeakHashMap line, which JDK 21 ignored completely.
The bottom two rows are the point of this post. No compiler lint and no JVM flag I could find reports == on two Integers, or a boxed value used as an IdentityHashMap key. Those bugs only appear when the code runs with the preview on and a test assertion notices the answer changed. If the result feeds a deduplication step, a cache key or a "has this object been seen" check, the first sign is wrong data, not an exception.
Where the identity bugs hide in a backend codebase
With this table in hand, three patterns stand out in ordinary Java and Kotlin backend code, and none of them are in code anyone would call clever.
Per-key locks are the first. A ConcurrentHashMap<Long, Object> of locks is fine. A lock map whose values are the boxed keys themselves, or a synchronized (orderId) on a Long, is the identity case. The pinning fix in JDK 24 made synchronized cheap enough to use with virtual threads again, which I wrote about in my notes on virtual threads after JEP 491. That makes this pattern more likely to come back, not less.
Weak caches keyed by dates or durations are the second. A WeakHashMap<LocalDate, Report> looks like a memory-friendly memo table. Under the preview it throws on the first put, and JDK 28's lint will now tell you so at compile time.
Object-graph walkers are the third, and the hardest to see. Serializers, deep-copy utilities, ORM dirty-checking and mocking frameworks track "visited" objects in an IdentityHashMap to break cycles. With boxed numbers and dates as value objects, two equal values collapse into one visited entry. A cycle-breaker may not care. Code that counts, tags or maps occurrences does. This is dependency code, so the only realistic check is running your test suite on a preview-enabled JDK and reading what fails.
There is also a cost on the other side. Turning on the preview to find these bugs means running a non-LTS JDK in CI, and preview class files only load on the exact release that compiled them. That is fine for a test job and wrong for a deployable artifact.
What changes when the preview lands in Java 29
If Goetz's estimate holds, Java 29 ships with value objects still in preview, and the plan for an LTS-only shop looks like this:
- Nothing changes for production by default. Without
--enable-preview, the four checks above gave the same answers on JDK 28 as on JDK 21, and JEP 401 behavior stays off. - Libraries will move first. Expect serialization, ORM and mocking libraries to publish preview-tested releases during the Java 29 cycle. Their changelogs are where identity assumptions will surface, so read them before your upgrade, not during it.
- Your CI can move now. One job on a JDK 28 early-access build with
--enable-previewand-Xlint:identityturns the loud bugs into failures, and gives the quiet ones a chance to fail an assertion if a test covers them. On a JDK 21 job, add-XX:+UnlockDiagnosticVMOptions -XX:DiagnoseSyncOnValueBasedClasses=2to log locks hidden behindObject. The unlock flag has to come first, or the JVM refuses to start. - Plan the real migration for the LTS after 29. If value objects finalize after Java 29, the first LTS where they work without a flag would be Java 33, if the two-year LTS cadence holds. Code written now should already avoid
==and locks on boxed andjava.timevalues, so it doesn't need a second pass then.
I covered the rest of what is heading into Java 29, from AOT caching to Lazy Constants, in my notes on Java 26 before the Java 29 LTS. That post was about what you gain. This one is about what assumptions you lose, and the quiet half of that list is what I would test first.
Still here? You might enjoy this.
Nothing close enough — try a different angle?
Related Posts
Java 26 Landed: The Features to Track Before the Java 29 LTS
Most backend teams run only the LTS lines, so Java 26 looks skippable. It is not — it is the clearest preview of what the Java 29 LTS will contain. These are my notes on what is already final (AOT object caching with ZGC, a faster G1, HTTP/3), the one preview I would rewrite code for (Lazy Constants, with a runnable example), and the integrity change that will break builds.
Kotlin 2.4: The Three Changes That Moved My Hand on the Keyboard
Kotlin 2.4.0 shipped a long changelog, but only three features changed how I actually type: stable context parameters, explicit backing fields, and (still behind a flag) name-based destructuring. Here is my backend-engineer's cut, verified against the 2.4.0 compiler, plus the K1 removal I had to put on a calendar.
Virtual Threads After JEP 491: The Bottleneck Moved
JEP 491 removed the `synchronized` pinning problem that kept virtual threads out of production. The interesting question now isn't whether to enable them — it's which bottleneck shows up next. A field guide for Spring Boot / Kotlin services running on JDK 24+.