20

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

3
  • what task are you using? I just ran a ./gradlew clean build on my machine and it resulted in a "BUILD SUCCESSFUL"
    – ligi
    Commented Jan 30, 2020 at 7:29
  • What do you mean by "task" ? I installed gradle 4.10.2 and kotlin 1.3.61. I run : gradle test Commented Jan 31, 2020 at 8:59
  • My Java environment is "openjdk version "11.0.5" 2019-10-15" Commented Jan 31, 2020 at 9:08

8 Answers 8

19

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
8

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>
7

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
3

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)

2

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
  • I don't see anything in the question to indicate this is an eclipse problem or that eclipse is even being used. Commented Nov 11, 2020 at 15:35
1

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.

1

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

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.

Not the answer you're looking for? Browse other questions tagged or ask your own question.