16

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!

0

1 Answer 1

29

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> 
Sign up to request clarification or add additional context in comments.

2 Comments

How to apply this when running a single Junit? I am getting error while running a particular junit.
In eclipse you can edit the run configuration to add the arguments to the JVM

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.