java-client-api icon indicating copy to clipboard operation
java-client-api copied to clipboard

Usage of JaCoCo plugin causes RuntimeException when tests are to be run from gradle/wrapper

Open georgeajit opened this issue 6 years ago • 3 comments

Version of MarkLogic Java Client API

develop

Version of MarkLogic Server

9.0 nightly server build

Java version

openjdk version "11" 2018-09-25 OpenJDK Runtime Environment 18.9 (build 11+28) OpenJDK 64-Bit Server VM 18.9 (build 11+28, mixed mode)

OS and version

NAME="Red Hat Enterprise Linux Server" VERSION="7.2 (Maipo)" ID="rhel" ID_LIKE="fedora" VERSION_ID="7.2" PRETTY_NAME="Red Hat Enterprise Linux Server 7.2 (Maipo)" ANSI_COLOR="0;31" CPE_NAME="cpe:/o:redhat:enterprise_linux:7.2:GA:server" HOME_URL="https://www.redhat.com/" BUG_REPORT_URL="https://bugzilla.redhat.com/"

REDHAT_BUGZILLA_PRODUCT="Red Hat Enterprise Linux 7" REDHAT_BUGZILLA_PRODUCT_VERSION=7.2 REDHAT_SUPPORT_PRODUCT="Red Hat Enterprise Linux" REDHAT_SUPPORT_PRODUCT_VERSION="7.2"

Input: Some code to illustrate the problem, preferably in a state that can be independently reproduced on our end

Run a gradle command to run a test. Make sure that gradle wrapper downloads Gradle 4.10 version.

Actual output: What did you observe? What errors did you see? Can you attach the logs? (Java logs, MarkLogic logs)

> Task :marklogic-client-api-functionaltests: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)
        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/util/UUID could not be instrumented.
        at org.jacoco.agent.rt.internal_773e439.core.runtime.ModifiedSystemClassRuntime.createFor(ModifiedSystemClassRuntime.java:139)
        at org.jacoco.agent.rt.internal_773e439.core.runtime.ModifiedSystemClassRuntime.createFor(ModifiedSystemClassRuntime.java:100)
        at org.jacoco.agent.rt.internal_773e439.PreMain.createRuntime(PreMain.java:55)
        at org.jacoco.agent.rt.internal_773e439.PreMain.premain(PreMain.java:47)
        ... 6 more
Caused by: java.lang.NoSuchFieldException: $jacocoAccess
        at java.base/java.lang.Class.getField(Class.java:2000)
        at org.jacoco.agent.rt.internal_773e439.core.runtime.ModifiedSystemClassRuntime.createFor(ModifiedSystemClassRuntime.java:137)
        ... 9 more
FATAL ERROR in native method: processing of -javaagent failed

Expected output: What specifically did you expect to happen?

The tests should be running.

Alternatives: What else have you tried, actual/expected?

Tried changing the JaCoCo version to be 0.8.1 and also tried to have no tool version in the apply plugin section of the build.gradle.

This time the exception was a little different. Posting those stack traces. Instead of java/util/UUID, we are seeing Class java/lang/UnknownError

> Task :marklogic-client-api-functionaltests: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)
        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:2000)
        at org.jacoco.agent.rt.internal_c13123e.core.runtime.ModifiedSystemClassRuntime.createFor(ModifiedSystemClassRuntime.java:138)
        ... 9 more
FATAL ERROR in native method: processing of -javaagent failed

georgeajit avatar Nov 14 '18 19:11 georgeajit

Found the following when searching for a solution:

https://github.com/jacoco/jacoco/issues/551

georgeajit avatar Nov 14 '18 19:11 georgeajit

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). Hope that helps anyone out there. https://stackoverflow.com/questions/59945979/java-lang-nosuchfieldexception-erreor-from-jacoco/64230649#64230649

mojicoj avatar Oct 06 '20 17:10 mojicoj

I notice that the 0.8.0 release of jacoco may have fixed some aspects of the issue and that the most recent release is 0.8.6

After we've confirmed that upgrading to Gradle 6.7 didn't introduce any regressions, should we experiment with the 0.8.6 or 0.8.5 jacoco plugin including adding:

  • the plugin in the parent build.gradle and
  • the report generation in marklogic-client-api-functionaltests/build.gradle

The usage may have changed in Gradle 6.7 and the jacoco 0.8.6 plugin. If so, the following command would report the deprecations in our usage:

./gradlew help --warning-mode all

For convenience, capturing the link for the jacoco plugin documentation:

https://docs.gradle.org/current/userguide/jacoco_plugin.html

ehennum avatar Nov 04 '20 23:11 ehennum

jacoco is no longer part of the project, removing

rjrudin avatar Nov 17 '22 15:11 rjrudin