Code coverage option "IDEA" makes unit tests fail

Hi everyone,

I have a problem using the code "IDEA" coverage option in JUnit tests. When code coverage is activated using "EMMA", everything works fine: The unit tests report successful testing, and the coverage result is displayed in the project browser. Anyhow, if I switch code coverage to "IDEA", all unit tests fail because of a NoClassDefFoundError. Following the stack trace:

Caused by: java.lang.NoClassDefFoundError: Could not initialize class net.sf.cglib.proxy.Enhancer
    at org.hibernate.proxy.pojo.cglib.CGLIBLazyInitializer.getProxyFactory(CGLIBLazyInitializer.java:117)
    at org.hibernate.proxy.pojo.cglib.CGLIBProxyFactory.postInstantiate(CGLIBProxyFactory.java:43)
    at org.hibernate.tuple.entity.PojoEntityTuplizer.buildProxyFactory(PojoEntityTuplizer.java:162)
    at org.hibernate.tuple.entity.AbstractEntityTuplizer.<init>(AbstractEntityTuplizer.java:135)
    at org.hibernate.tuple.entity.PojoEntityTuplizer.<init>(PojoEntityTuplizer.java:55)
    at org.hibernate.tuple.entity.EntityEntityModeToTuplizerMapping.<init>(EntityEntityModeToTuplizerMapping.java:56)
    at org.hibernate.tuple.entity.EntityMetamodel.<init>(EntityMetamodel.java:302)
    at org.hibernate.persister.entity.AbstractEntityPersister.<init>(AbstractEntityPersister.java:434)
    at org.hibernate.persister.entity.SingleTableEntityPersister.<init>(SingleTableEntityPersister.java:109)
    at org.hibernate.persister.PersisterFactory.createClassPersister(PersisterFactory.java:55)
    at org.hibernate.impl.SessionFactoryImpl.<init>(SessionFactoryImpl.java:226)
    at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1300)
    at org.springframework.orm.hibernate3.LocalSessionFactoryBean.newSessionFactory(LocalSessionFactoryBean.java:814)
    at org.springframework.orm.hibernate3.LocalSessionFactoryBean.buildSessionFactory(LocalSessionFactoryBean.java:732)
    at org.springframework.orm.hibernate3.AbstractSessionFactoryBean.afterPropertiesSet(AbstractSessionFactoryBean.java:211)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1369)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1335)
    ... 41 more

The tests are JUnit4 tests, and I use annotations to inject Spring services. Is there maybe some incompability with the IDEA code coverage plugin?

Regards,
Stephan

9 comments
Comment actions Permalink

Hello,

Do you use Language Injection with runtime instrumentation?

Thank you

-


Anna Kozlova
JetBrains Inc.
http://www.intellij.com
"Develop with pleasure!"

Hi everyone,

I have a problem using the code "IDEA" coverage option in JUnit tests.
When code coverage is activated using "EMMA", everything works fine:
The unit tests report successful testing, and the coverage result is
displayed in the project browser. Anyhow, if I switch code coverage to
"IDEA", all unit tes

ts fail because of a NoClassDefFoundError. Following the stack trace:

Caused by: java.lang.NoClassDefFoundError: Could not initialize class
net.sf.cglib.proxy.Enhancer
at
org.hibernate.proxy.pojo.cglib.CGLIBLazyInitializer.getProxyFactory(CG
LIBLazyInitializer.java:117)
at
org.hibernate.proxy.pojo.cglib.CGLIBProxyFactory.postInstantiate(CGLIB
ProxyFactory.java:43)
at
org.hibernate.tuple.entity.PojoEntityTuplizer.buildProxyFactory(PojoEn
tityTuplizer.java:162)
at
org.hibernate.tuple.entity.AbstractEntityTuplizer.<init>(AbstractEntit
yTuplizer.java:135)
at
org.hibernate.tuple.entity.PojoEntityTuplizer.<init>(PojoEntityTuplize
r.java:55)
at
org.hibernate.tuple.entity.EntityEntityModeToTuplizerMapping.<init>(En
tityEntityModeToTuplizerMapping.java:56)
at
org.hibernate.tuple.entity.EntityMetamodel.<init>(EntityMetamodel.java
:302)
at
org.hibernate.persister.entity.AbstractEntityPersister.<init>(Abstract
EntityPersister.java:434)
at
org.hibernate.persister.entity.SingleTableEntityPersister.<init>(Singl
eTableEntityPersister.java:109)
at
org.hibernate.persister.PersisterFactory.createClassPersister(Persiste
rFactory.java:55)
at
org.hibernate.impl.SessionFactoryImpl.<init>(SessionFactoryImpl.java:2
26)
at
org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java
:1300)
at
org.springframework.orm.hibernate3.LocalSessionFactoryBean.newSessionF
actory(LocalSessionFactoryBean.java:814)
at
org.springframework.orm.hibernate3.LocalSessionFactoryBean.buildSessio
nFactory(LocalSessionFactoryBean.java:732)
at
org.springframework.orm.hibernate3.AbstractSessionFactoryBean.afterPro
pertiesSet(AbstractSessionFactoryBean.java:211)
at
org.springframework.beans.factory.support.AbstractAutowireCapableBeanF
actory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1369)
at
org.springframework.beans.factory.support.AbstractAutowireCapableBeanF
actory.initializeBean(AbstractAutowireCapableBeanFactory.java:1335)
... 41 more
The tests are JUnit4 tests, and I use annotations to inject Spring
services. Is there maybe some incompability with the IDEA code
coverage plugin?

Regards,
Stephan
---
Original message URL:
http://www.jetbrains.net/devnet/message/5232281#5232281



0
Comment actions Permalink

I use the @Runtime annotation to inject the Spring services. Is this a problem?

Regards,
Stephan

0
Comment actions Permalink

Stephan,

I suspect that there are multiple runtime instrumentations.

Could you please try to disable File|Settings|Language Injection|Advanced|
Runtime instrumentation?

Thanks

-


Anna Kozlova
JetBrains Inc.
http://www.intellij.com
"Develop with pleasure!"

I use the @Runtime annotation to inject the Spring services. Is this a
problem?

Regards,
Stephan
---
Original message URL:
http://www.jetbrains.net/devnet/message/5232286#5232286



0
Comment actions Permalink

Hi Anna,

I changed to settings to "No runtime instrumentation". However, the result (and the stack trace output) remains the same. Configuration "EMMA" works fine, "IDEA" does not work at all.

Regards,
Stephan

0
Comment actions Permalink

Stephen,

Sorry I forgot to ask to recompile corresponding class. Does it help? Do
you have any other runtime instrumentations enabled?

Or may be you can provide sources of that class?

Thank you

-


Anna Kozlova
JetBrains Inc.
http://www.intellij.com
"Develop with pleasure!"

Hi Anna,

I changed to settings to "No runtime instrumentation". However, the
result (and the stack trace output) remains the same. Configuration
"EMMA" works fine, "IDEA" does not work at all.

Regards,
Stephan
---
Original message URL:
http://www.jetbrains.net/devnet/message/5232295#5232295



0
Comment actions Permalink

Hi Anna,

I already had recompiled the classes so the settings does not seem to solve the problem. I think that the whole problem has something to do with the cglib library of Hibernate. I have set up a test project at home without Hibernate, and the unit tests run without any problems using the IDEA code coverage routine. On another small project (using Hibernate and the cglib library) the tests fail with IDEA code coverage. There was another stack trace that may help you:

Caused by: java.lang.NoSuchMethodError: org.objectweb.asm.ClassWriter.<init>(Z)V
at net.sf.cglib.core.DebuggingClassWriter.<init>(DebuggingClassWriter.java:47)
at net.sf.cglib.core.DefaultGeneratorStrategy.getClassWriter(DefaultGeneratorStrategy.java:30)
at net.sf.cglib.core.DefaultGeneratorStrategy.generate(DefaultGeneratorStrategy.java:24)
at net.sf.cglib.core.AbstractClassGenerator.create(AbstractClassGenerator.java:216)
at net.sf.cglib.core.KeyFactory$Generator.create(KeyFactory.java:145)
at net.sf.cglib.core.KeyFactory.create(KeyFactory.java:117)
at net.sf.cglib.core.KeyFactory.create(KeyFactory.java:108)
at net.sf.cglib.core.KeyFactory.create(KeyFactory.java:104)
at net.sf.cglib.proxy.Enhancer.<clinit>(Enhancer.java:69)
at org.hibernate.proxy.pojo.cglib.CGLIBLazyInitializer.getProxyFactory(CGLIBLazyInitializer.java:117)
at org.hibernate.proxy.pojo.cglib.CGLIBProxyFactory.postInstantiate(CGLIBProxyFactory.java:43)
at org.hibernate.tuple.entity.PojoEntityTuplizer.buildProxyFactory(PojoEntityTuplizer.java:162)
at org.hibernate.tuple.entity.AbstractEntityTuplizer.<init>(AbstractEntityTuplizer.java:135)
at org.hibernate.tuple.entity.PojoEntityTuplizer.<init>(PojoEntityTuplizer.java:55)
at org.hibernate.tuple.entity.EntityEntityModeToTuplizerMapping.<init>(EntityEntityModeToTuplizerMapping.java:56)
at org.hibernate.tuple.entity.EntityMetamodel.<init>(EntityMetamodel.java:302)
at org.hibernate.persister.entity.AbstractEntityPersister.<init>(AbstractEntityPersister.java:434)
at org.hibernate.persister.entity.SingleTableEntityPersister.<init>(SingleTableEntityPersister.java:109)
at org.hibernate.persister.PersisterFactory.createClassPersister(PersisterFactory.java:55)
at org.hibernate.impl.SessionFactoryImpl.<init>(SessionFactoryImpl.java:226)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1300)
at org.springframework.orm.hibernate3.LocalSessionFactoryBean.newSessionFactory(LocalSessionFactoryBean.java:814)
at org.springframework.orm.hibernate3.LocalSessionFactoryBean.buildSessionFactory(LocalSessionFactoryBean.java:732)
at org.springframework.orm.hibernate3.AbstractSessionFactoryBean.afterPropertiesSet(AbstractSessionFactoryBean.java:211)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1368)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1334)
... 40 more


In the project, I am using Spring's dynamic proxies and interceptors to set up transactional behaviour. Is this maybe the problem? Following you will find the relevant part from the Spring configuration:

<bean id="sessionFactory" >
  <description>The Hibernate session factory.</description>
  <property name="dataSource" ref="dataSource"/>
  <property name="mappingLocations">
   <list>
    <value>classpath:/com/lhsystems/projektor/integration/user/User.hbm.xml</value>
    <value>classpath:/com/lhsystems/projektor/integration/user/Department.hbm.xml</value>
    <value>classpath:/com/lhsystems/projektor/integration/project/Project.hbm.xml</value>
   </list>
  </property>
  <property name="hibernateProperties">
   <props>
    <prop key="hibernate.dialect">org.hibernate.dialect.MySQL5Dialect</prop>
    <prop key="hibernate.show_sql">false</prop>
    <prop key="hibernate.format_sql">false</prop>
   </props>
  </property>
</bean>


<bean id="transactionManager" >
  <description>The transaction manager.</description>
  <property name="sessionFactory" ref="sessionFactory"/>
</bean>


<bean name="serviceTransactionInterceptor"
     scope="singleton">
  <description>The transaction interceptor for all service bean.</description>
  <property name="transactionManager" ref="transactionManager"/>
  <property name="transactionAttributeSource">
   <bean >
    <property name="transactionAttribute"
        value="PROPAGATION_REQUIRED,ISOLATION_DEFAULT,timeout_120,-Exception"/>
   </bean>
  </property>
</bean>


<bean id="autoProxyCreator" >
  <description>
   The automatic proxy creator that creates a proxy for each service bean and sets the transaction
   interceptor.
  </description>
  <property name="beanNames" value="*Service"/>
  <property name="interceptorNames">
   <list>
    <value>serviceTransactionInterceptor</value>
   </list>
  </property>
</bean>


Any idea?

Regards,
Stephan

0
Comment actions Permalink

Any news on this?

Regards,
Stephan

0
Comment actions Permalink

I have the same problem trying to use the IDEA code coverage tool. The Emma coverage option works for me.

Since the error I get refers to a package "sun", I assumed the reason I can't use this tool is simply because I'm not using a Sun JVM. (I'm on Mac OS X, which uses Apple's VM)

   Exception in thread "main" java.lang.NoClassDefFoundError: sun/reflect/GeneratedConstructorAccessor1

-Kay

0
Comment actions Permalink

I'm seeing the opposite on one of my tests.  The EMMA decoration of my classes is resulting in scenarios where introspection doesn't notice all of my setters.

0

Please sign in to leave a comment.