Since upgradting to Java 17 my unit test that are using EasyMock are failing with to the following exception
java.lang.NoClassDefFoundError: Could not initialize class org.easymock.internal.ClassProxyFactory$2 at org.easymock.internal.ClassProxyFactory.createEnhancer(ClassProxyFactory.java:233) at org.easymock.internal.ClassProxyFactory.createProxy(ClassProxyFactory.java:165) at org.easymock.internal.MocksControl.createMock(MocksControl.java:107) at org.easymock.internal.MocksControl.createMock(MocksControl.java:80) at org.easymock.EasyMockSupport.mock(EasyMockSupport.java:77) at org.easymock.EasyMockSupport.createMock(EasyMockSupport.java:364)
I am running the tests using maven-surefire-plugin.
Update: as of EasyMock 5.0.0
add-opensis not required anymore.Issues #274 and #300 have been resolved with version 5.0.0.
So upgrading to EasyMock version 5 solves the issue.
Java 17 contains JEP 403 which strongly encapsulates JDK Internals.
As EasyMock uses some of these internal APIs access to these need to be made accessable by setting the command line option
add-openshttps://docs.oracle.com/javase/9/migrate/toc.htm
As pointed out in this EasyMock issue
So to fix the exception
add-opensneeds to be set asargLinefor the maven-surefire-plugin