17

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

Abhishek Ramachandran
  • 1,160
  • 1
  • 13
  • 34
Emile Achadde
  • 1,715
  • 3
  • 10
  • 22

7 Answers7

17

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.

tschumann
  • 2,776
  • 3
  • 26
  • 42
  • 1
    Thanks! Here are the [most recent versions](https://www.eclemma.org/jacoco/) of jacoco, if anyone wants them. – Brad Turek Sep 30 '22 at 22:39
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.

julianm
  • 2,393
  • 1
  • 23
  • 24
7

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>
Jimson James
  • 2,937
  • 6
  • 43
  • 78
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.

Emile Achadde
  • 1,715
  • 3
  • 10
  • 22
1

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.

yuvaraj
  • 11
  • 3
1

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)

Rkumar
  • 19
  • 7
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

Josef Vancura
  • 1,053
  • 10
  • 18