ERROR: "Method <clinit> is not static in class file" with instrumented jars

263 views
Skip to first unread message

omprakash...@gmail.com

unread,
May 6, 2019, 6:38:42 AM5/6/19
to JaCoCo and EclEmma Users
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?

Evgeny Mandrikov

unread,
May 6, 2019, 7:03:15 AM5/6/19
to JaCoCo and EclEmma Users
There is absolutely nothing unusual.
 


Any Idea?



I'm pretty sure that if you'll try the same without JaCoCo, then you'll observe exactly the same problem, which means that it is not caused by JaCoCo.

Because your problem looks very similar to the following bug in JMockit - https://github.com/jmockit/jmockit1/issues/590
which according to http://jmockit.github.io/changes.html was fixed in JMockit version 1.46.

omprakash...@gmail.com

unread,
May 6, 2019, 8:36:36 AM5/6/19
to JaCoCo and EclEmma Users
Hi Mandrikov,

Thanks for the insights on this issue. I completely overlooked the existing jmockit bug.

With the jmockit 1.46, the issue is gone.

Thanks again

omprakash...@gmail.com

unread,
May 6, 2019, 9:04:17 AM5/6/19
to JaCoCo and EclEmma Users


On Monday, May 6, 2019 at 4:33:15 PM UTC+5:30, Evgeny Mandrikov wrote:
Here do you mean i should try without instrumentation or with some other instrumentation tools? 

Evgeny Mandrikov

unread,
May 6, 2019, 2:42:14 PM5/6/19
to JaCoCo and EclEmma Users

On Monday, May 6, 2019 at 3:04:17 PM UTC+2, omprakash...@gmail.com wrote:

I'm pretty sure that if you'll try the same without JaCoCo, then you'll observe exactly the same problem, which means that it is not caused by JaCoCo.

Here do you mean i should try without instrumentation or with some other instrumentation tools? 

Not "with some other tool",
just without instrumentation by JaCoCo,
which is a very good way to understand that problem is not caused by JaCoCo.

And now you don't need to try anything, because you already know that problem was caused by bug in JMockit.
Reply all
Reply to author
Forward
This conversation is locked
You cannot reply and perform actions on locked conversations.
0 new messages