I am having some issue with Mocking a class instrumented with jacoco. 
Problem:
 1. Junit Testcase Mocking a class with some static final fields.
 2. Class under Test is instrumented with jacoco-0.8.3
 3. Mocking is done using jmockit-1.44
 4. Using OpenJDK-11.0.1
 5. Test fails with **"Method <clinit> is not static in class file"**
 6. Test pass with JDK-1.8

Here is the stacktrace

Method <clinit> is not static in class file $Subclass_ClassUnderTest

java.lang.ClassFormatError: Method <clinit> is not static in class file 
$Subclass_ClassUnderTest
at java.base/java.lang.ClassLoader.defineClass1(Native Method)
at java.base/java.lang.ClassLoader.defineClass(ClassLoader.java:1016)
at java.base/java.lang.ClassLoader.defineClass(ClassLoader.java:877)
at ClassUnderTestTestcase$3.<init>(ClassUnderTestTestcase.java:xx)
at ClassUnderTestTestcase.testSettersAndGetters(ClassUnderTestTestcase.java:xx)



I tried to investigate the bytecode and found something unusual(i guess)

**With Java 11**

    // access flags 0x100A
      private static synthetic $jacocoInit()[Z
        GETSTATIC ClassUnderTest.$jacocoData : [Z
        DUP
        IFNONNULL L0
        POP
        LDC -1475355800743669619
        LDC "ClassUnderTest"
        BIPUSH 64
        INVOKESTATIC org/jacoco/agent/rt/internal_1f1cc91/Offline.getProbes 
(JLjava/lang/String;I)[Z
        DUP
        PUTSTATIC ClassUnderTest.$jacocoData : [Z
       L0

**With Java8**

        // access flags 0x100A
      private static synthetic $jacocoInit()[Z
        GETSTATIC ClassUnderTest.$jacocoData : [Z
        DUP
        IFNONNULL L0
        POP
        LDC 4330111099009117958
        LDC "ClassUnderTest"
        BIPUSH 64
        INVOKESTATIC org/jacoco/agent/rt/internal_1f1cc91/Offline.getProbes 
(JLjava/lang/String;I)[Z
        DUP
        PUTSTATIC ClassUnderTest.$jacocoData : [Z
       L0


Any Idea?

-- 
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 [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/jacoco/b550255f-b2b9-4297-b096-9665cb594f18%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to