java version:17 mockito version:5.3.0
As I am upgrading to java 17, junit test cases are failing with reason:
Caused by: java.lang.reflect.InaccessibleObjectException: Unable to make protected final java.lang.Class java.lang.ClassLoader.defineClass(java.lang.String,byte[],int,int,java.security.ProtectionDomain) throws java.lang.ClassFormatError accessible: module java.base does not "opens java.lang" to unnamed module @38cccef
Please suggest some solution as I CANNOT use solutions:
- —add-opens java.base/java.lang=ALL-UNNAMED or
- --illegal-access=permit (removed in java 17)
I am expecting to solve this problem by adding any new dependency in pom.xml or different version of mockito. with minimal code change.
-
Please clarify your specific problem or provide additional details to highlight exactly what you need. As it's currently written, it's hard to tell exactly what you're asking.Community– Community Bot2023年05月17日 15:02:43 +00:00Commented May 17, 2023 at 15:02
2 Answers 2
add this to pom:
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>3.1.0</version>
<configuration>
<argLine>--add-opens java.base/java.lang=ALL-UNNAMED</argLine>
</configuration>
</plugin>
</plugins>
</build>
1 Comment
—add-opens, now your "solution" is exactly that.Follow the instructions in the mockito release notes under '5.0.0' here. Essentially, switch the mockmaker implementation.
That, or downgrade back to JDK11.