Clover Knowledge Base : "Could not initialize class" error at runtime


Execution of tests or a standalone application terminates with an error message similar to the following:

Could not initialize class com.acme.MyClass$__CLR3_2_02t2thng9gff

or from Maven:

    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(
    at java.lang.reflect.Method.invoke(
    at org.codehaus.mojo.exec.ExecJavaMojo$
Caused by: java.lang.NoClassDefFoundError: Could not initialize class com.acme.MyClass$__CLR3_2_02t2thng9gffc

or from JBoss:

org.jboss.arquillian.container.spi.client.container.DeploymentException: Could not deploy to container: ...
Caused by: javax.persistence.PersistenceException: ...
Caused by: org.hibernate.MappingException: Could not get constructor for org.hibernate.persister.entity.SingleTableEntityPersister
Caused by: org.hibernate.InstantiationException: could not instantiate test <some test name>
Caused by: java.lang.reflect.InvocationTargetException
Caused by: java.lang.NoClassDefFoundError: Could not initialize class com.acme.MyEntity$__CLR3_1_12b0b0hlfzxawo



In 99% of cases this is caused by a fact that clover.jar is missing in runtime. Please keep in mind that it's not enough to have clover.jar during compilation - classes instrumented by Clover needs Clover's core classes from clover.jar during application (or test) execution.

Please have a look at solutions in a related article: NoClassDefFoundError com_atlassian_clover/CoverageRecorder.