Powermockito compatibility with JDK 17

8,897 views
Skip to first unread message

sanchit relan

unread,
Nov 9, 2021, 5:05:15 AM11/9/21
to PowerMock
Hi,

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.

Thanks and Regards
Sanchit

Дмитрий Ларионов

unread,
Nov 11, 2022, 1:34:38 AM11/11/22
to PowerMock
The issues like that are introduced with Java modularization Understanding Java 9 Modules (oracle.com).

You can use JVM options --add-opens to open certain JAVA classes for your tests. To your pom.xml add the following:

    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-surefire-plugin</artifactId>
                <configuration>
                    <argLine>
                        --add-opens java.base/java.lang=ALL-UNNAMED
                        --add-opens java.base/java.time=ALL-UNNAMED
                        --add-opens java.base/java.time.format=ALL-UNNAMED
                        --add-opens java.base/java.util=ALL-UNNAMED
                    </argLine>
                </configuration>
            </plugin>
        </plugins>
    </build>

Tune argLine for your need.

вторник, 9 ноября 2021 г. в 13:05:15 UTC+3, srel...@gmail.com:
Reply all
Reply to author
Forward
0 new messages