Unlock Java 21: New Features, Virtual Threads, and Migration Tips
Java 21, the latest LTS release, introduces virtual threads, sequenced collections, record patterns, and other enhancements; the article explains these new features, guides developers on configuring IDEs and runtimes with Azul Zulu and IntelliJ IDEA, and resolves Lombok incompatibility by updating to version 1.18.30.
1. Introduction
Java 21 was officially released on September 20, 2023 as the next LTS version after Java 17. Virtual threads become a standard feature, and Spring Boot 3.2 can enable them by setting
spring.threads.virtual.enabled=true. Java 21 is expected to become as popular as Java 8.
2. Java 21 Feature Updates
2.1 Official Features
Virtual Threads
Sequenced Collections
Record Patterns
Pattern Matching for switch
Generational ZGC
Deprecate the Windows 32‑bit x86 Port for Removal
Prepare to Disallow the Dynamic Loading of Agents
Key Encapsulation Mechanism API
3. Switching Development Environment to Java 21
The author uses the Azul Zulu distribution.
IntelliJ IDEA 2023.2.2 is required to configure the Java 21 environment.
4. Lombok Incompatibility with Java 21
When compiling the PIGX project, the following error occurs:
<code>An annotation processor threw an uncaught exception.
Consult the following stack trace for details.
java.lang.NoSuchFieldError: Class com.sun.tools.javac.tree.JCTree$JCImport does not have member field 'com.sun.tools.javac.tree.JCTree qualid'
at lombok.javac.JavacImportList.getFullyQualifiedNameForSimpleNameNoAliasing(JavacImportList.java:53)
at lombok.core.TypeResolver.typeRefToFullyQualifiedName(TypeResolver.java:60)
at lombok.javac.HandlerLibrary.handleAnnotation(HandlerLibrary.java:247)
at lombok.javac.JavacTransformer$AnnotationVisitor.visitAnnotationOnType(JavacTransformer.java:79)
at lombok.javac.JavacNode.traverse(JavacNode.java:132)
at lombok.javac.JavacAST.traverseChildren(JavacAST.java:222)
</code>Updating Lombok to the latest version 1.18.30 resolves the issue. Because PIGX uses a unified BOM for dependency management, the version can be updated globally in the common‑bom.
Java Architecture Diary
Committed to sharing original, high‑quality technical articles; no fluff or promotional content.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.