Horcrux7
Horcrux7

Reputation: 24477

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)

Upvotes: 3

Views: 2183

Answers (2)

Horcrux7
Horcrux7

Reputation: 24477

We solve the problem by updating JMockit version 1.31 with the current version 1.44. It look like the old version is not compatible with the current version.

Upvotes: 1

joemokenela
joemokenela

Reputation: 299

Try to run it by adding the following command argument.

--add-reads java.base=java.desktop

Upvotes: 2

Related Questions