305 questions
395 votes
17 answers
489k views
Compilation error after upgrading to JDK 21 - "NoSuchFieldError: JCImport does not have member field JCTree qualid"
After upgrading to JDK 21, I have the following compilation error in my Spring Boot project: Fatal error compiling: java.lang.NoSuchFieldError: Class com.sun.tools.javac.tree.JCTree$JCImport does not ...
58 votes
10 answers
41k views
Getting "A Java agent has been loaded dynamically" warning in IntelliJ after upgrading Java 17 to 21
I have just upgraded from JDK 17 to 21 in my Windows machine. After that when I am running JUNIT test and I am getting the following warring. I have looked over all of the day, but no solution worked ...
46 votes
7 answers
89k views
Starting from which version does Gradle support Java 21?
When trying to configure the project using Java 21 I'm getting the error: Unsupported Java. Your build is currently configured to use Java 21 and Gradle 8.3. Unfortunately, there is no information ...
29 votes
3 answers
15k views
What @Nullable to use in Java (as of 2023/JDK21)?
As of 2023/JDK21, what @Nullable to use in Java? Many online materials don't even mention which import to use. So it is now (dark) history in what order those annotation appeared. I hope for general ...
22 votes
7 answers
64k views
Can't use latest Java Version (JDK 21) in IntelliJ IDEA
I'm using macOS and I want to try Java 21 in IntelliJ IDEA. I believe I have done all the required steps to change Java version of a project / module. Nevertheless I still can't use new Java 21 ...
21 votes
1 answer
1k views
Why does pattern matching with switch on InetAddress fail with 'does not cover all possible input values'?
In Java 21 and 23, java.net.InetAddress is declared public sealed class InetAddress implements Serializable permits Inet4Address, Inet6Address { However, the following code: switch (addr) { case ...
20 votes
1 answer
6k views
Java 21 built-in HTTP client pins the carrier thread
I'm using Java Corretto 21.0.0.35.1 build 21+35-LTS, and the built-in Java HTTP client to retrieve a response as an InputStream. I'm making parallel requests using virtual threads, and for the most ...
17 votes
1 answer
30k views
IntelliJ IDEA + JDK 21 issue with java.util.concurrent package - TimeUnit class not available
I have an issue when I am trying to use TimeUnit class from java.util.concurrent. It happens with Oracle JDK 21.0.1 (configurations are below) + IntelliJ IDEA 2023.1.5 (Community Edition) - the latest ...
15 votes
2 answers
2k views
Why doesn't Java 21's EnumSet implement the new SequencedSet interface?
When Java 21 introduced sequenced collections, I was really excited to start using them. But then I quickly found that there are various corners of the JDK where it seems like the new sequenced ...
15 votes
2 answers
5k views
Java 21 problem with DateFormat.getDateTimeInstance().format(new Date())
This is my code import java.util.Date; import java.text.DateFormat; class DateTime { public static void main(String[] args) { String dt = DateFormat.getDateTimeInstance().format(new Date()...
12 votes
2 answers
387 views
Increased memory consumption due to String Constant Pool behavior after upgrading from Java 17 to Java 21
While upgrading our project from Java 17 to Java 21, we noticed an increase in memory consumption. After dumping the heap and analyzing the differences, I found that there are thousands of empty ...
10 votes
1 answer
6k views
Java 21 guarded pattern exhaustiveness
I started to play with the new Java 21 feature - pattern matching. public class Main { public static void main(String[] args) { RecordB recordB = new RecordB(true); switch(recordB) { ...
9 votes
2 answers
3k views
Should virtual thread die fast?
It' s recommended by JDK developers that virtual threads should never be pooled, because they are really cheap to create and destroy. I am a little confusing about the pooling idea, since pooling ...
9 votes
1 answer
433 views
Java 21 Regex Word-boundary matcher Unicode change
I noticed that the semantics of the Java Regex word-boundary matcher \b changed significantly with Java 21. Up until (at least) Java 17, it used to support Unicode, so the regex a\b.* DID NOT match ...
8 votes
2 answers
12k views
Java 21 virtual thread executor performing worse than executor with pooled OS threads?
I have just upgraded our Spring Boot applications to Java 21. As a part of that, I have also done changes to use virtual threads. Both when serving API requests and when doing async operations ...