apex2022
apex2022

Reputation: 855

Error message mentions Java 9 even though I am using Java 11

I have a Java 11 Gradle project for work. I am using IntelliJ Idea. I have some test errors, so I'm trying to debug. The error message I'm asking about appears to be unrelated to the test errors, but I could be wrong and it still bothers me. Here is the message:

java.lang.IllegalStateException: Running on JDK 9 requires -javaagent:<proper path>/jmockit-1.n.jar or -Djdk.attach.allowAttachSelf
    at java.base/java.util.ServiceLoader$ProviderImpl.newInstance(ServiceLoader.java:780)
    at java.base/java.util.ServiceLoader$ProviderImpl.get(ServiceLoader.java:722)
    at java.base/java.util.ServiceLoader$3.next(ServiceLoader.java:1395)
    at java.base/java.lang.Iterable.forEach(Iterable.java:74)
    at org.gradle.api.internal.tasks.testing.junitplatform.JUnitPlatformTestClassProcessor$CollectAllTestClassesExecutor.processAllTestClasses(JUnitPlatformTestClassProcessor.java:97)
    at org.gradle.api.internal.tasks.testing.junitplatform.JUnitPlatformTestClassProcessor$CollectAllTestClassesExecutor.access$000(JUnitPlatformTestClassProcessor.java:79)
    at org.gradle.api.internal.tasks.testing.junitplatform.JUnitPlatformTestClassProcessor.stop(JUnitPlatformTestClassProcessor.java:75)
    at org.gradle.api.internal.tasks.testing.SuiteTestClassProcessor.stop(SuiteTestClassProcessor.java:61)
    at org.gradle.internal.dispatch.ReflectionDispatch.dispatch(ReflectionDispatch.java:36)
    at org.gradle.internal.dispatch.ReflectionDispatch.dispatch(ReflectionDispatch.java:24)
    at org.gradle.internal.dispatch.ContextClassLoaderDispatch.dispatch(ContextClassLoaderDispatch.java:33)
    at org.gradle.internal.dispatch.ProxyDispatchAdapter$DispatchingInvocationHandler.invoke(ProxyDispatchAdapter.java:94)
    at org.gradle.api.internal.tasks.testing.worker.TestWorker.stop(TestWorker.java:133)
    at org.gradle.internal.dispatch.ReflectionDispatch.dispatch(ReflectionDispatch.java:36)
    at org.gradle.internal.dispatch.ReflectionDispatch.dispatch(ReflectionDispatch.java:24)
    at org.gradle.internal.remote.internal.hub.MessageHubBackedObjectConnection$DispatchWrapper.dispatch(MessageHubBackedObjectConnection.java:182)
    at org.gradle.internal.remote.internal.hub.MessageHubBackedObjectConnection$DispatchWrapper.dispatch(MessageHubBackedObjectConnection.java:164)
    at org.gradle.internal.remote.internal.hub.MessageHub$Handler.run(MessageHub.java:414)
    at org.gradle.internal.concurrent.ExecutorPolicy$CatchAndRecordFailures.onExecute(ExecutorPolicy.java:64)
    at org.gradle.internal.concurrent.ManagedExecutorImpl$1.run(ManagedExecutorImpl.java:48)
    at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128)
    at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628)
    at org.gradle.internal.concurrent.ThreadFactoryImpl$ManagedThreadRunnable.run(ThreadFactoryImpl.java:56)
    at java.base/java.lang.Thread.run(Thread.java:834)

I have looked at Settings, Project Structure, and all of the Jars in the External Libraries. I see everything saying Java 11. I see nothing saying Java 9. Is this a message I would expect to get even in Java 11? Is it a message I don't need to worry about? Are there any places besides Settings, Project Structure and the JARs that I need to check?

Upvotes: 2

Views: 533

Answers (1)

kriegaex
kriegaex

Reputation: 67317

Your question is completely unrelated to IntelliJ IDEA. You just happen to be running your tests from there. Instead, you should have mentioned that you use JMockit in your tests, which is clearly the root cause for your problems, if you just fully read the error message instead of stopping at "JDK 9", which, like Johannes said, means "JDK >= 9":

java.lang.IllegalStateException:
  Running on JDK 9 requires
    -javaagent:<proper path>/jmockit-1.n.jar
    or -Djdk.attach.allowAttachSelf

Not only do you read "jmockit" in the error message, but also two possible solutions. Have you tried any of them?

By the way, the error message mentions JDK 9, because that was the version which introduced JPMS (Java Platform Module System). JEP 261: Module System, which was part of JDK 9, reads:

The com.sun.tools.attach API can no longer be used, by default, to attach an agent to the current process or an ancestor of the current process. Such attachment operations can be enabled by setting the system property jdk.attach.allowAttachSelf on the command line.

This changes the way how to dynamically attach a Java agent to a running JVM without -javaagent command line parameter, especially to self-attachment, i.e. the JVM initiating the attachment is also the target JVM. JMockit makes use of that technology, which is why you either need to set that system property for JDK 9+ or use the traditional approach of declaring the JMockit agent on the command line. Both options are easy enough to implement.

Upvotes: 2

Related Questions