java.lang.NoSuchFieldException error from jacoco

36.2k views Asked by At

I am trying to run the tests of the kotlin code provided from here : https://github.com/ligi/ipfs-api-kotlin 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 java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
FATAL ERROR in native method: processing of -javaagent failed, processJavaStart failed
        at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.base/java.lang.reflect.Method.invoke(Method.java:566)
        at java.instrument/sun.instrument.InstrumentationImpl.loadClassAndStartAgent(InstrumentationImpl.java:513)
        at java.instrument/sun.instrument.InstrumentationImpl.loadClassAndCallPremain(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 java.base/java.lang.Class.getField(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

8

There are 8 answers

0
julianm On

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! enter image description here enter image description here

Hope that helps someone out there.

0
Rkumar On

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)

0
Emile Achadde On

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.

0
Josef Vancura On

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

enter image description here

0
Jimson James On

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>
1
tschumann On

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.

0
Sam YC On

For my case, I am having java 11 and 17 in my machine, and my JAVA_HOME is poiting to java 17, although I have specify java 11 in my gradle like below:

sourceCompatibility = JavaVersion.VERSION_11
targetCompatibility = JavaVersion.VERSION_11

and

jacoco {
    toolVersion = "0.8.2"
}

I still faced the same issue, so I updated my JAVA_HOME to point it to the location of my java SDK 11, then it is working fine.

1
yuvaraj On

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.