1

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:

  1. —add-opens java.base/java.lang=ALL-UNNAMED or
  2. --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.

James Z
12.3k10 gold badges28 silver badges50 bronze badges
asked May 17, 2023 at 13:37
1
  • 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. Commented May 17, 2023 at 15:02

2 Answers 2

3

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>
answered May 18, 2023 at 10:31
Sign up to request clarification or add additional context in comments.

1 Comment

In your question you said you can’t use —add-opens, now your "solution" is exactly that.
0

Follow the instructions in the mockito release notes under '5.0.0' here. Essentially, switch the mockmaker implementation.

That, or downgrade back to JDK11.

Jorn Vernee
34.3k5 gold badges84 silver badges99 bronze badges
answered May 17, 2023 at 13:48

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.