Java. Lang. Nosuchfieldexception Error from Jacoco

I am trying to run the tests of the kotlin code provided from here : with gradlew

I got the error listed below. Could someone tell me what this error means ?

> Task :test FAILED
Exception in thread "main" java.lang.reflect.InvocationTargetException
        at (Native Method)
        at (NativeMethodAccessorImpl.java:62)
FATAL ERROR in native method: processing of -javaagent failed, processJavaStart failed
        at (DelegatingMethodAccessorImpl.java:43)
        at (Method.java:566)
        at (InstrumentationImpl.java:513)
        at (InstrumentationImpl.java:525)
Caused by: java.lang.RuntimeException: Class java/lang/UnknownError could not be instrumented.
        at org.jacoco.agent.rt.internal_c13123e.core.runtime.ModifiedSystemClassRuntime.createFor(ModifiedSystemClassRuntime.java:140)
        at org.jacoco.agent.rt.internal_c13123e.core.runtime.ModifiedSystemClassRuntime.createFor(ModifiedSystemClassRuntime.java:101)
        at org.jacoco.agent.rt.internal_c13123e.PreMain.createRuntime(PreMain.java:55)
        at org.jacoco.agent.rt.internal_c13123e.PreMain.premain(PreMain.java:47)
        ... 6 more
Caused by: java.lang.NoSuchFieldException: $jacocoAccess
        at (Class.java:1999)
        at org.jacoco.agent.rt.internal_c13123e.core.runtime.ModifiedSystemClassRuntime.createFor(ModifiedSystemClassRuntime.java:138)
        ... 9 more
*** java.lang.instrument ASSERTION FAILED ***: "result" with message agent load/premain call failed at  line: 422

3

7 Answers

I was missing the following from my build.gradle:

jacoco {
    toolVersion = "0.8.6"
}

While obvious, build.gradle can inherit properties from other gradle files and for reasons I can't figure out, jacoco was passing through in to one subproject but not to another.

1

Ensure you are using JDK-11, if using maven, ensure;

<maven.compiler.source>11</maven.compiler.source>
<maven.compiler.target>11</maven.compiler.target>

Ensure you are using latest jacoco.

        <groupId>org.jacoco</groupId>
        <artifactId>jacoco-maven-plugin</artifactId>
        <version>0.8.4</version>

Fixed this error changing Java SDK in my project from 14 to 11 and my tests started working fine.

Solution: IntellijIDEA: File > Project Structure > Project Tab > SDK adopt-opendjdk-11 (in my case for Ubuntu).

Oh! Make sure Gradle Settings are also using the same JVM!

Hope that helps someone out there.

0

I had similar issue when I upgraded my jdk1.8 to openjdk11 but it was solved by updating the toolVersion = "0.8.6" (used toolVersion = "0.8.1" with jdk1.8)

The issue comes from the Java version which needs not to be too recent.

sdk install java 19.3.0.2.r8-grl

makes things ok.

After followed below steps it's working fine for me.

In Eclipse,Go to Window--Preferences--java.Right-click on installed JRE. There add an installed JDK path & remove others.

1

Fix in my case was to download and install Java 8 (jdk1.8.0_301) and set it in Project Settings

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Elena Rostova

Elena Rostova

Lead Health, Wellness & Medical Journalist

Elena Rostova holds a Master's degree in Public Health Journalism. She covers groundbreaking medical research, holistic wellness trends, mental health awareness, and nutritional science.

Share this article
Twitter Facebook Pinterest