Upgrading across an LTS
The best argument is not a feature: it is a NullPointerException that names which of four dereferences was null.
Java releases every six months and designates one every two years as long-term support. Teams do not upgrade every six months; they jump from one LTS to the next — 8 to 11, 11 to 17, 17 to 21 — and each jump is a project with a shape worth knowing before you start.
What you actually get, on one line of code
Here is the argument for upgrading, and it is not a feature list. The same program, the same line, with four dereferences on it:
orders.get("A-1").customer.address.city.length()On Java 8:
Exception in thread "main" java.lang.NullPointerException
at Npe.main(Npe.java:13)On a modern JDK:
Exception in thread "main" java.lang.NullPointerException: Cannot read field "city"
because "java.util.Map.get(Object).customer.address" is null
at Npe.main(Npe.java:13)The first tells you a line. The second tells you which dereference, by name, on a line with four candidates.
Multiply that by every production NPE your team will ever debug. That is a better argument than records and pattern matching, because it costs nothing to adopt — it is on by default and requires no code change at all.
The same is true of most of what an upgrade buys: a newer garbage collector, better JIT output, smaller container images, and startup improvements all arrive without a line being written. The language features are the part you choose; the runtime improvements are the part you get.
The two upgrades that are actually different
8 → 11 is the hard one, and it is hard for one reason: Java 9 modularised the JDK and removed things that used to be there.
- The Java EE modules are gone. JAXB, JAX-WS,
javax.annotation, CORBA. This is the most common break, and the fix is adding them as ordinary dependencies — they live on Maven Central now. - Internal APIs are enforced.
sun.misc.Unsafeand friends were always unsupported; from 9 they are genuinely inaccessible, and the illegal-access warnings became errors in 16. - The version string changed.
1.8.0_292became11.0.19. Anything parsing it breaks, and something always is. - The class-file version changes, which is the
UnsupportedClassVersionErrorthe class-file lesson is about.
11 → 17 and 17 → 21 are ordinary. Mostly they are dependency upgrades, a build plugin or two, and a check for removed methods. Teams that have done 8 → 11 are usually surprised by how small the next ones are.
The order that works
- Upgrade dependencies first, on the old JDK. Most upgrade failures are a library that does not understand the new class-file version, and fixing that while everything else is stable is far easier than debugging it alongside a JDK change. Spring Boot, the build plugins, anything doing bytecode manipulation — Lombok, Mockito, ByteBuddy, ASM — are the usual suspects.
- Compile with the new JDK, target the old release.
--release 11on a Java 17 compiler proves your code compiles without committing to the new bytecode. Note--releaserather than-source/-target: it also checks you are not using APIs that did not exist in the target. - Run the tests on the new JDK, still targeting the old. This is where bytecode-manipulating libraries fail, and it is the step that finds most problems.
- Deploy with the new runtime, old target. Now you have the GC and JIT improvements with no code change and a rollback that is one config value.
- Only then raise the target and start using new language features.
Each step is separately revertible, which is the whole point. A single change that moves compiler, runtime and language level at once has one outcome to debug and one thing to roll back: everything.
What tends to break
- Bytecode manipulation. Anything reading or writing class files needs a version that knows the new format.
- Reflection into the JDK. Frameworks reaching into
java.baseneed--add-opens, and each one should be a ticket rather than a permanent flag. - The default garbage collector changed to G1 in Java 9. If you had tuned for Parallel or CMS, those flags are wrong or gone — CMS was removed in 14.
- Date formatting. The default locale data provider changed to CLDR in Java 9, so some formatted dates differ. It is small, it is real, and it surfaces in a test that compares strings.
Stringgot compact strings in Java 9, which halves the memory for Latin-1 text and changes nothing you can observe except the heap.
Which LTS to be on
Be on an LTS, and be no more than one behind. The reason is not features; it is that security patches stop, and an unpatched JDK is the vulnerable-dependency lesson's subject at the bottom of your stack.
The distribution matters too and is easy to get wrong: Oracle's JDK has licence terms that have changed more than once. Temurin, Corretto, Zulu, Liberica and Microsoft's build are all OpenJDK and free, and any of them is a fine answer.
Under the hood: what --release actually checks, and how the LTS cadence is decided
"Compile with the new JDK, target the old release" above leans on --release, and the reason it is safer than -source/-target is worth being precise about. -source 11 -target 11 on a Java 17 compiler only changes the language-level parser rules and the output class-file version — it says nothing about which API you call. Nothing stops you calling a method added in Java 15 while targeting 11's bytecode, and that code compiles cleanly, then throws NoSuchMethodError the day it actually runs on a Java 11 JVM. --release 11 closes that gap: the compiler substitutes the actual ct.sym symbol file bundled in the JDK — a snapshot of every version's public API surface, one entry per release — for the classpath the running compiler would otherwise expose, so calling a Java 15-only method under --release 11 is a compile error, not a run-time surprise four months later. That symbol file is also why --release requires no separate JDK 11 installation: the Java 17 compiler carries every earlier release's API shape with it.
The LTS cadence itself is a release-process decision, not a technical one baked into the JDK: since Java 9, a new feature release ships every six months on a fixed date, and every JDK 9+ class file records the exact feature version it targets (the class-file major version, one higher per release — 55 for Java 11, 61 for Java 17, 65 for Java 21 — which is the specific number an UnsupportedClassVersionError names). Oracle and the OpenJDK community separately designate roughly every other year's September release as long-term-supported, meaning security patches continue past the point a non-LTS release stops receiving any; the six-month train runs regardless, LTS or not, and "jump from one LTS to the next" is a policy choice about which of those trains you board, not a difference in what the trains contain.
Try it yourself
Which step catches which failure?
A team is doing 11 → 17. Two problems turn up: (1) a Lombok version too old to understand Java 17 class files, generating garbage bytecode silently; (2) a third-party library calling sun.misc.Unsafe.defineClass, removed in later JDKs, that only executes on one rarely-hit code path. Match each to the step in the lesson's upgrade order that actually catches it, and explain why the other steps do not.
Answer
The Lombok problem is caught by step 1, "upgrade dependencies first, on the old JDK" — but only if the team notices the newer Lombok fixes the issue; more precisely, it is exposed by step 3 ("run the tests on the new JDK") if step 1 is skipped, because a bytecode-manipulating library that does not understand the new class-file format is exactly the kind of failure that only appears once that library actually runs against classes compiled by (or loaded on) the new JDK — a --release 17 compile alone would not catch it, since --release checks API surface, not whether an annotation processor's generated bytecode is well-formed. The sun.misc.Unsafe problem is the harder one: since the path is rarely hit, step 2 (--release compile) does not catch it — --release's symbol file covers supported public API, and code reaching Unsafe via reflection rather than a direct method call is invisible to the compiler either way — and step 3 only catches it if the test suite actually exercises that rare path. This is the practical argument for running the new runtime in a staging or canary environment under real traffic before step 4's full deploy: --release and unit tests both check what they can see statically or in covered paths, and reflective access to removed internals is neither.
Misconceptions
- "
-source/-targetand--releasedo the same job,--releaseis just newer syntax."-source/-targetonly change the language and class-file version;--releaseadditionally substitutes the target version's own API symbol table, so it catches "compiles fine, throwsNoSuchMethodErrorat runtime" bugs that-source/-targetcannot see at all. - "Every six-month release is a small, skippable step." Each one changes the class-file major version and can remove or change APIs (structured concurrency's shape moved between previews, as the preview lesson shows) — "skippable" describes whether you adopt new language features from it, not whether code compiled or reflecting against its internals stays safe to run unchanged on the next one.
Sources
javaccommand-line documentation — the--releaseoption and its symbol-file (ct.sym) semantics, versus-source/-target.- The Java Virtual Machine Specification, §4.1 ("The
ClassFileStructure") — the class-file major-version field and its meaning. - Oracle's Java SE support roadmap and the OpenJDK release cadence documentation — the six-month feature-release train and how an LTS designation is layered on top of it.
java.lang.DeprecatedJavadoc — theforRemovalelement this lesson's-Xlint:deprecationadvice depends on.