Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to prevent java.lang.IllegalAccessError with JDK11?

We receive the follow exception in our test system. Any idea how we can prevent this exception for example with a command line switch. And any idea how this exception can occur?

Can the completely access check be disabled in a test system that use intensively reflection and class loading?

java.lang.IllegalAccessError: class java.io.File (in module java.base) cannot access class javax.print.PrintException (in module java.desktop) because module java.base does not read module java.desktop
    at java.io.File.exists(File.java)
    at jdk.internal.loader.URLClassPath$FileLoader.getResource(URLClassPath.java:1199)
    at jdk.internal.loader.URLClassPath.getResource(URLClassPath.java:314)
    at jdk.internal.loader.BuiltinClassLoader.findClassOnClassPathOrNull(BuiltinClassLoader.java:697)
    at jdk.internal.loader.BuiltinClassLoader.loadClassOrNull(BuiltinClassLoader.java:623)
    at jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:581)
    at jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:178)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:521)
    at java.lang.Class.forName0(Native Method)
    at java.lang.Class.forName(Class.java:398)
    at org.gradle.api.internal.tasks.testing.junit.JUnitTestClassExecutor.runTestClass(JUnitTestClassExecutor.java:67)
    at org.gradle.api.internal.tasks.testing.junit.JUnitTestClassExecutor.execute(JUnitTestClassExecutor.java:58)
    at org.gradle.api.internal.tasks.testing.junit.JUnitTestClassExecutor.execute(JUnitTestClassExecutor.java:38)
    at org.gradle.api.internal.tasks.testing.junit.AbstractJUnitTestClassProcessor.processTestClass(AbstractJUnitTestClassProcessor.java:66)
like image 666
Horcrux7 Avatar asked Jan 26 '26 10:01

Horcrux7


1 Answers

Try to run it by adding the following command argument.

--add-reads java.base=java.desktop
like image 63
joemokenela Avatar answered Jan 29 '26 00:01

joemokenela



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!