Broken stock jacoco plugin

The stock jacoco plugin appears to fail to support the newer versions of Java, as of Java 14.

build.gradle:

plugins {
    id 'jacoco'
}

apply plugin: 'java'
sourceCompatibility = '1.14'

dependencies {
    testImplementation 'junit:junit:4.13.2'
    testImplementation 'org.apache.logging.log4j:log4j:2.17.2'
}

Build report:

$ gradle build

> Task :test
java.lang.instrument.IllegalClassFormatException: Error while instrumenting sun/util/resources/cldr/provider/CLDRLocaleDataMetaInfo.
        at org.jacoco.agent.rt.internal_3570298.CoverageTransformer.transform(CoverageTransformer.java:94)
        at java.instrument/java.lang.instrument.ClassFileTransformer.transform(ClassFileTransformer.java:244)
        at java.instrument/sun.instrument.TransformerManager.transform(TransformerManager.java:188)
        at java.instrument/sun.instrument.InstrumentationImpl.transform(InstrumentationImpl.java:541)
        at java.base/java.lang.ClassLoader.defineClass2(Native Method)
        at java.base/java.lang.ClassLoader.defineClass(ClassLoader.java:1104)
        at java.base/java.security.SecureClassLoader.defineClass(SecureClassLoader.java:182)
        at java.base/jdk.internal.loader.BuiltinClassLoader.defineClass(BuiltinClassLoader.java:821)
        at java.base/jdk.internal.loader.BuiltinClassLoader.findClassInModuleOrNull(BuiltinClassLoader.java:741)
        at java.base/jdk.internal.loader.BuiltinClassLoader.findClass(BuiltinClassLoader.java:621)
        at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:633)
        at java.base/java.lang.Class.forName(Class.java:577)
        at java.base/java.lang.Class.forName(Class.java:552)
        at java.base/java.util.ServiceLoader.loadProvider(ServiceLoader.java:859)
        at java.base/java.util.ServiceLoader$ModuleServicesLookupIterator.hasNext(ServiceLoader.java:1084)
        at java.base/java.util.ServiceLoader$2.hasNext(ServiceLoader.java:1309)
        at java.base/java.util.ServiceLoader$3.hasNext(ServiceLoader.java:1393)
        at java.base/sun.util.cldr.CLDRLocaleProviderAdapter.lambda$new$0(CLDRLocaleProviderAdapter.java:86)
        at java.base/java.security.AccessController.doPrivileged(AccessController.java:569)
        at java.base/sun.util.cldr.CLDRLocaleProviderAdapter.<init>(CLDRLocaleProviderAdapter.java:85)
        at java.base/jdk.internal.reflect.DirectConstructorHandleAccessor.newInstance(DirectConstructorHandleAccessor.java:67)
        at java.base/java.lang.reflect.Constructor.newInstanceWithCaller(Constructor.java:499)
        at java.base/java.lang.reflect.Constructor.newInstance(Constructor.java:483)
        at java.base/sun.util.locale.provider.LocaleProviderAdapter.forType(LocaleProviderAdapter.java:188)
        at java.base/sun.util.locale.provider.LocaleProviderAdapter.findAdapter(LocaleProviderAdapter.java:287)
        at java.base/sun.util.locale.provider.LocaleProviderAdapter.getAdapter(LocaleProviderAdapter.java:258)
        at java.base/java.util.Calendar.createCalendar(Calendar.java:1688)
        at java.base/java.util.Calendar.getInstance(Calendar.java:1656)
        at java.base/java.text.SimpleDateFormat.initializeCalendar(SimpleDateFormat.java:680)
        at java.base/java.text.SimpleDateFormat.<init>(SimpleDateFormat.java:624)
        at java.base/java.text.SimpleDateFormat.<init>(SimpleDateFormat.java:603)
        at org.gradle.process.internal.worker.child.SystemApplicationClassLoaderWorker.getLastResortErrorLogFile(SystemApplicationClassLoaderWorker.java:162)
        at org.gradle.process.internal.worker.child.SystemApplicationClassLoaderWorker.call(SystemApplicationClassLoaderWorker.java:111)
        at org.gradle.process.internal.worker.child.SystemApplicationClassLoaderWorker.call(SystemApplicationClassLoaderWorker.java:71)
        at worker.org.gradle.process.internal.worker.GradleWorkerMain.run(GradleWorkerMain.java:69)
        at worker.org.gradle.process.internal.worker.GradleWorkerMain.main(GradleWorkerMain.java:74)
Caused by: java.io.IOException: Error while instrumenting sun/util/resources/cldr/provider/CLDRLocaleDataMetaInfo.
        at org.jacoco.agent.rt.internal_3570298.core.instr.Instrumenter.instrumentError(Instrumenter.java:160)
        at org.jacoco.agent.rt.internal_3570298.core.instr.Instrumenter.instrument(Instrumenter.java:110)
        at org.jacoco.agent.rt.internal_3570298.CoverageTransformer.transform(CoverageTransformer.java:92)
        ... 35 more
Caused by: java.lang.IllegalArgumentException: Unsupported class file major version 62
        at org.jacoco.agent.rt.internal_3570298.asm.ClassReader.<init>(ClassReader.java:196)
        at org.jacoco.agent.rt.internal_3570298.asm.ClassReader.<init>(ClassReader.java:177)
        at org.jacoco.agent.rt.internal_3570298.asm.ClassReader.<init>(ClassReader.java:163)
        at org.jacoco.agent.rt.internal_3570298.core.internal.instr.InstrSupport.classReaderFor(InstrSupport.java:280)
        at org.jacoco.agent.rt.internal_3570298.core.instr.Instrumenter.instrument(Instrumenter.java:76)
        at org.jacoco.agent.rt.internal_3570298.core.instr.Instrumenter.instrument(Instrumenter.java:108)
        ... 36 more

BUILD SUCCESSFUL in 1s
6 actionable tasks: 6 executed

I just hit this issue with JDK 18 even when using JaCoCo 0.8.8 which is supposed to support JDK 18. Is this a bug in the Gradle plugin? Any suggestions for a workaround @mcandre?

Actually unlikely.
Especially from the stack trace of OP, it is during test execution, so Gradle shouldn’t be involved at that time regarding that.
If you are sure you use 0.8.8 properly, maybe you found a JaCoCo bug?
Did you try to run with JaCoCo without Gradle in the loop?
Can you show an MCVE where it fails?

Thanks for the help! Actually the issue was with my build.gradle file. I had set version 0.8.8 to be used in the subprojects that I wanted however I was also running a jacocoRootReport task to aggregate reports which, however, was defined in the root project which didn’t have a toolVersion setup. I guess Gradle used the default JaCoCo version for that (which is not 0.8.8) so it blew up. That’s my guess at least, haven’t dug much deeper than that.

1 Like