Expand my Community achievements bar.

Issues After Upgrading to JDK 21 and JUnit 5 in AEM Project – Need Guidance

Avatar

Level 2

Hi all,

Previously, I was using JDK 11 and JUnit 4 in the AEM project source code, and all the core module test cases were passing. However, after upgrading to JDK 21 and JUnit 5, all the test cases started failing with several issues such as NullPointerException, NoClassDefFoundError, and others. For your reference, I have attached a screenshot.

I want to investigate why this happened and how we can fix it. Do we need to resolve these null and NoClassDefFoundError issues manually by visiting each and every failing class, or is there any other way?

 

Murali__D_2-1762929388235.pngMurali__D_3-1762929410514.png

 

Please provide proper guidance. Thanks

2 Replies

Avatar

Level 10

Hi @Murali__D,

Upgrading Java may be painless, but upgrading to JUnit 5 is not an easy task and requires many code changes. The most likely root causes in your case include:

I warmly suggest that you take a look at these articles, which contain step-by-step instructions on how to do the upgrades.

Avatar

Employee Advisor

Hello @Murali__D ,

 

After the upgrade from JDK 11 + JUnit 4 to JDK 21 + JUnit 5, the test failures you are seeing (NullPointerException, NoClassDefFoundError, etc.) are expected. This happens because several dependencies, test frameworks, and plugins used earlier are not fully compatible with Java 21 or JUnit 5.

You do not need to fix each failing class manually. The root cause is the test setup itself, not the individual test logic.

>To resolve the issue, you will need to:

  1. Update the Maven Surefire/Failsafe plugins to versions that support JUnit 5 and JDK 21.

  2. Add the required JUnit 5 (jupiter) dependencies.

  3. Upgrade Mockito/PowerMock/ByteBuddy libraries to versions compatible with Java 21.

  4. Add back any libraries that were removed from the JDK (e.g., JAXB) if your tests use them.

Once the test framework and dependencies are updated, most of the failures will be resolved automatically. Only a few tests may require manual fixes afterward.

If you share your pom.xml or one full stacktrace, I can check further.