got IllegalStateException: Cannot process instrumented class ... Please supply original non-instrumented classes

166 views
Skip to first unread message

Lin Ma

unread,
Nov 4, 2021, 7:10:16 AM11/4/21
to JaCoCo and EclEmma Users
It is said this from jaCoco, but dont what it needs to do differently with android studio (fox) 2020.3.1.

it is much appreciated if someone could help.
The details and log are below:

Having an android library project, it has been built and unit tested fine with android studio 4.1.2. Now change to use android studio (fox) 2020.3.1 path 3.

It starts to get error `Cannot run gradle test tasks because of java.lang.NoClassDefFoundError: jdk/internal/reflect/GeneratedSerializationConstructorAccessor1`.

after added `task.jacoco.excludes = ['jdk.internal.*']`:
```
plugins.withId("jacoco") {
        tasks.withType(Test) { task ->
            task.jacoco.includeNoLocationClasses = true
            task.jacoco.excludes = ['jdk.internal.*'] //<=== added this line
        }
    }
```
the error disappeared, but now got:
```
java.lang.instrument.IllegalClassFormatException: Error while instrumenting com/mobile/notification/NotificationModule.
        at org.jacoco.agent.rt.internal_f3994fa.CoverageTransformer.transform(CoverageTransformer.java:94)
        at java.instrument/java.lang.instrument.ClassFileTransformer.transform(ClassFileTransformer.java:246)
        at java.instrument/sun.instrument.TransformerManager.transform(TransformerManager.java:188)
        at java.instrument/sun.instrument.InstrumentationImpl.transform(InstrumentationImpl.java:563)
        at java.base/java.lang.ClassLoader.defineClass1(Native Method)
        at java.base/java.lang.ClassLoader.defineClass(ClassLoader.java:1016)
        at java.base/java.security.SecureClassLoader.defineClass(SecureClassLoader.java:151)
        at java.base/jdk.internal.loader.BuiltinClassLoader.defineClass(BuiltinClassLoader.java:802)
        at java.base/jdk.internal.loader.BuiltinClassLoader.findClassOnClassPathOrNull(BuiltinClassLoader.java:700)
        at java.base/jdk.internal.loader.BuiltinClassLoader.loadClassOrNull(BuiltinClassLoader.java:623)
        at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:581)
        at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:178)
.........

        Caused by: java.io.IOException: Error while instrumenting com/mobile/notification/NotificationModule.
        at org.jacoco.agent.rt.internal_f3994fa.core.instr.Instrumenter.instrumentError(Instrumenter.java:160)
        at org.jacoco.agent.rt.internal_f3994fa.core.instr.Instrumenter.instrument(Instrumenter.java:110)
        at org.jacoco.agent.rt.internal_f3994fa.CoverageTransformer.transform(CoverageTransformer.java:92)
        ... 64 more
        Caused by: java.lang.IllegalStateException: Cannot process instrumented class com/mobile/notification/NotificationModule. Please supply original non-instrumented classes.
        at org.jacoco.agent.rt.internal_f3994fa.core.internal.instr.InstrSupport.assertNotInstrumented(InstrSupport.java:238)
        at org.jacoco.agent.rt.internal_f3994fa.core.internal.instr.ClassInstrumenter.visitField(ClassInstrumenter.java:56)
        at org.jacoco.agent.rt.internal_f3994fa.asm.ClassVisitor.visitField(ClassVisitor.java:339)
        at org.jacoco.agent.rt.internal_f3994fa.asm.ClassReader.readField(ClassReader.java:1111)
        at org.jacoco.agent.rt.internal_f3994fa.asm.ClassReader.accept(ClassReader.java:713)
        at org.jacoco.agent.rt.internal_f3994fa.asm.ClassReader.accept(ClassReader.java:401)
        at org.jacoco.agent.rt.internal_f3994fa.core.instr.Instrumenter.instrument(Instrumenter.java:90)
        at org.jacoco.agent.rt.internal_f3994fa.core.instr.Instrumenter.instrument(Instrumenter.java:108)
        ... 65 more

[Robolectric] WARN: Android SDK 16 requires Java 8 (have Java 1). Tests won't be run on SDK 16 unless explicitly requested.
[Robolectric] WARN: Android SDK 17 requires Java 8 (have Java 1). Tests won't be run on SDK 17 unless explicitly requested.
[Robolectric] WARN: Android SDK 18 requires Java 8 (have Java 1). Tests won't be run on SDK 18 unless explicitly requested.
[Robolectric] WARN: Android SDK 19 requires Java 8 (have Java 1). Tests won't be run on SDK 19 unless explicitly requested.
[Robolectric] WARN: Android SDK 21 requires Java 8 (have Java 1). Tests won't be run on SDK 21 unless explicitly requested.
[Robolectric] WARN: Android SDK 22 requires Java 8 (have Java 1). Tests won't be run on SDK 22 unless explicitly requested.
[Robolectric] WARN: Android SDK 23 requires Java 8 (have Java 1). Tests won't be run on SDK 23 unless explicitly requested.
[Robolectric] WARN: Android SDK 24 requires Java 8 (have Java 1). Tests won't be run on SDK 24 unless explicitly requested.
[Robolectric] WARN: Android SDK 25 requires Java 8 (have Java 1). Tests won't be run on SDK 25 unless explicitly requested.
[Robolectric] WARN: Android SDK 26 requires Java 8 (have Java 1). Tests won't be run on SDK 26 unless explicitly requested.
[Robolectric] WARN: Android SDK 27 requires Java 8 (have Java 1). Tests won't be run on SDK 27 unless explicitly requested.
[Robolectric] WARN: Android SDK 28 requires Java 8 (have Java 1). Tests won't be run on SDK 28 unless explicitly requested.
[Robolectric] WARN: Android SDK 29 requires Java 9 (have Java 1). Tests won't be run on SDK 29 unless explicitly requested.

Failed to create a Robolectric sandbox: Android SDK 28 requires Java 8 (have Java 1)
java.lang.UnsupportedOperationException: Failed to create a Robolectric sandbox: Android SDK 28 requires Java 8 (have Java 1)
at org.robolectric.RobolectricTestRunner.getSandbox(RobolectricTestRunner.java:265)
at org.robolectric.RobolectricTestRunner.getSandbox(RobolectricTestRunner.java:63)
at org.robolectric.internal.SandboxTestRunner$2.evaluate(SandboxTestRunner.java:215)
at org.junit.runners.BlockJUnit4ClassRunner$1.evaluate(BlockJUnit4ClassRunner.java:100)
at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:366)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:103)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:63)
at org.junit.runners.ParentRunner$4.run(ParentRunner.java:331)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:79)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:329)
at org.junit.runners.ParentRunner.access$100(ParentRunner.java:66)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:293)
at org.robolectric.internal.SandboxTestRunner$1.evaluate(SandboxTestRunner.java:96)
at org.junit.runners.ParentRunner.run(ParentRunner.java:413)
at org.gradle.api.internal.tasks.testing.junit.JUnitTestClassExecutor.runTestClass(JUnitTestClassExecutor.java:110)
at org.gradle.api.internal.tasks.testing.junit.JUnitTestClassExecutor.execute(JUnitTestClassExecutor.java:58)
at org.gradle.api.internal.tasks.testing.junit.JUnitTestClassExecutor.execute(JUnitTestClassExecutor.java:38)
at org.gradle.api.internal.tasks.testing.junit.AbstractJUnitTestClassProcessor.processTestClass(AbstractJUnitTestClassProcessor.java:62)
at org.gradle.api.internal.tasks.testing.SuiteTestClassProcessor.processTestClass(SuiteTestClassProcessor.java:51)
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:567)
at org.gradle.internal.dispatch.ReflectionDispatch.dispatch(ReflectionDispatch.java:36)
at org.gradle.internal.dispatch.ReflectionDispatch.dispatch(ReflectionDispatch.java:24)
at org.gradle.internal.dispatch.ContextClassLoaderDispatch.dispatch(ContextClassLoaderDispatch.java:33)
at org.gradle.internal.dispatch.ProxyDispatchAdapter$DispatchingInvocationHandler.invoke(ProxyDispatchAdapter.java:94)
at com.sun.proxy.$Proxy5.processTestClass(Unknown Source)
at org.gradle.api.internal.tasks.testing.worker.TestWorker.processTestClass(TestWorker.java:119)
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:567)
at org.gradle.internal.dispatch.ReflectionDispatch.dispatch(ReflectionDispatch.java:36)
at org.gradle.internal.dispatch.ReflectionDispatch.dispatch(ReflectionDispatch.java:24)
at org.gradle.internal.remote.internal.hub.MessageHubBackedObjectConnection$DispatchWrapper.dispatch(MessageHubBackedObjectConnection.java:182)
at org.gradle.internal.remote.internal.hub.MessageHubBackedObjectConnection$DispatchWrapper.dispatch(MessageHubBackedObjectConnection.java:164)
at org.gradle.internal.remote.internal.hub.MessageHub$Handler.run(MessageHub.java:414)
at org.gradle.internal.concurrent.ExecutorPolicy$CatchAndRecordFailures.onExecute(ExecutorPolicy.java:64)
at org.gradle.internal.concurrent.ManagedExecutorImpl$1.run(ManagedExecutorImpl.java:48)
at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128)
at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628)
at org.gradle.internal.concurrent.ThreadFactoryImpl$ManagedThreadRunnable.run(ThreadFactoryImpl.java:56)
at java.base/java.lang.Thread.run(Thread.java:835)


```

the project has 
```
compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }
```
and
```


android {
    compileSdkVersion 30
    buildToolsVersion 30.0.0

    defaultConfig {
        minSdkVersion 21
        targetSdkVersion 30
        versionCode 1
        versionName version

        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
        
    }
```
and other related:
```

        classpath "com.android.tools.build:gradle:4.1.2"

        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:1.4.30"
        classpath 'com.google.gms:google-services:4.3.4'
        classpath "org.jacoco:org.jacoco.core:0.8.7"

...
testImplementation "junit:junit:4.13.2"
testApi "org.robolectric:robolectric:4,3,1"
```

what does the error `IllegalStateException: Cannot process instrumented class ... Please supply original non-instrumented classes.` mean?  and why it complains about it has `have Java 1` where there is `JavaVersion.VERSION_1_8` specified?

in the project's resource folder it also has `robolectric.properties` which has `sdk=28` to ask it using api version 28.

question is what might be missing, since it has been working fine in android studio 4.1.2.

Marc Hoffmann

unread,
Nov 4, 2021, 7:15:55 AM11/4/21
to JaCoCo and EclEmma Users
Hi,

the error says, that you try to instrument a class which has already be instrumented by JaCoCo. This is typically a build misconfiguration.

In your case it happens in the JaCoCo agent. So there can be two errors:

1) The classes in disk are already instrumented (offline instrumentation)
2) You provide two JaCoCo agents to the JVM

Regards,
-marc

--
You received this message because you are subscribed to the Google Groups "JaCoCo and EclEmma Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jacoco+un...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/jacoco/b9ed7f3e-f130-42a0-b655-d08cc1ce5315n%40googlegroups.com.

Lin Ma

unread,
Nov 4, 2021, 7:48:53 AM11/4/21
to JaCoCo and EclEmma Users
Thank you Marc. i am not familiar with jaCoCo, do you know how to find out if it is one of these two cases? Why it has been working fine with  old android studio 4.1.2, only now with android studio 2020.3 it starts to fail.

Marc Hoffmann

unread,
Nov 4, 2021, 7:55:43 AM11/4/21
to jac...@googlegroups.com
Hi, I really can’t tell you: The JaCoCo integration in Android Studio is not done by us and I have never used it. Maybe you better check with the project behind Android Studio.

Sorry,
-marc

Lin Ma

unread,
Nov 4, 2021, 10:24:34 AM11/4/21
to JaCoCo and EclEmma Users
when tried with testApi "org.robolectric:robolectric:4,6,1", the "it has `have Java 1`" not show anymore.

how to point to original non-instrumentated classe, "Caused by: java.lang.IllegalStateException: Cannot process instrumented class com/oath/mobile/shadowfax/Shadowfax. Please supply original non-instrumented classes".
Reply all
Reply to author
Forward
0 new messages