Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Module java.base does not "opens java.lang" (Java 17.0.4.1) [duplicate]

Tags:

java

java-17

Here's the error: Caused by: java.lang.reflect.InaccessibleObjectException: Unable to make protected java.lang.ClassLoader() accessible: module java.base does not "opens java.lang" to unnamed module @75dcbabb

Also, I'm using maven to compile. Thank you for reading this thread! Hope you can help me out with this!

like image 261
SunnyVN Avatar asked Dec 30 '25 00:12

SunnyVN


1 Answers

On java 17 there are some higher restrictions for some internal modules.

I'm not sure if you have this issue on the implementation code or "just" for testing. From my experience this issue is more common for the tests because most mocking frameworks will break the restrictions...

However you have to give in these parameters

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

If you need this for unit testing you and using maven then you could use a configuration like this:

    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-surefire-plugin</artifactId>
                <version>3.0.0</version>
                <configuration>
                    <argLine>
                        --add-opens=java.base/java.lang=ALL-UNNAMED
                        --add-opens=java.base/java.util=ALL-UNNAMED
                    </argLine>
                </configuration>
            </plugin>
        </plugins>
    </build>
like image 108
snap Avatar answered Dec 31 '25 18:12

snap



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!