Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Powermock Compatibility with JDK 17

Recently I was upgrading my project from JDK 11 to JDK 17. After upgrading, powermock seems to have an issue. While running AUT's , I am getting following error:

java.lang.RuntimeException: PowerMock internal error: Should never throw exception at this level
Caused by: java.lang.reflect.InaccessibleObjectException: Unable to make protected native java.lang.Object java.lang.Object.clone() throws java.lang.CloneNotSupportedException accessible: module java.base does not "opens java.lang" to unnamed module @3fc34119

Do you know any workaround this issue, If so can you please provide the solution.

like image 784
sanchit relan Avatar asked Sep 06 '25 22:09

sanchit relan


1 Answers

As a stop gap measure (until Powermock gets updated), you should be able to run your tests by passing the following argument to your JVM:

--add-opens java.base/java.lang=ALL-UNNAMED

If you're running your tests with Maven, you can configure the surefire-plugin like this:

<plugin>
  <artifactId>maven-surefire-plugin</artifactId>
  <version>${plugin.surefire.version}</version>
  <configuration>
    <argLine>--add-opens java.base/java.lang=ALL-UNNAMED</argLine>
  </configuration>
</plugin>
like image 65
julmud Avatar answered Sep 08 '25 11:09

julmud