Problem
When running a test, the following error appears:
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 @XXXXXX
Cause
The error is caused by the implementation of strong encapsulation introduced in the Java Platform Module System, introduced with Java 9. By default, certain internal APIs are not accessible unless explicitly opened.
When running the test using the green Run arrow next to the test method (as described here), you might need to pass the specific VM option.
The steps below explain how to add this option to the test run configuration.
Resolution
To fix this, add the required --add-opens VM option to your run configuration:
-
Go to Run | Edit Configurations...
-
Click the Modify options drop-down.
-
Enable Add VM options.
-
In the VM options field, enter:
--add-opens=java.base/java.lang=ALL-UNNAMED -
Save and rerun the test.
Reference: Stack Overflow: How to solve InaccessibleObjectException
Comments
0 comments
Please sign in to leave a comment.