Cobertura Issue



Failure while instrumented class file, with tools:
cobertura-1.9.4.1
jdk java version 1.6.0_30
Apache Ant(TM) version 1.8.2







[tutorial@tutorialhost coveragereport]$ ant
Buildfile: /coveragereport/build.xml

init:
    [mkdir] Created dir: /coveragereport/instrumented
    [mkdir] Created dir: /coveragereport/htmlReports

InstrumentEARLib:
[cobertura-instrument] Cobertura 1.9.4.1 - GNU GPL License (NO WARRANTY) - See COPYRIGHT file
[cobertura-instrument] Instrumenting 19368 files to /coveragereport/instrumented
[cobertura-instrument] WARN   addInstrumentationToSingleClass, Unable to instrument file /StructureLoader.class
[cobertura-instrument] java.lang.RuntimeException: java.lang.ClassNotFoundException: WarningNode
[cobertura-instrument]  at org.objectweb.asm.ClassWriter.getCommonSuperClass(Unknown Source)
[cobertura-instrument]  at org.objectweb.asm.ClassWriter.a(Unknown Source)
[cobertura-instrument]  at org.objectweb.asm.Frame.a(Unknown Source)
[cobertura-instrument]  at org.objectweb.asm.Frame.a(Unknown Source)
[cobertura-instrument]  at org.objectweb.asm.MethodWriter.visitMaxs(Unknown Source)
[cobertura-instrument]  at org.objectweb.asm.ClassReader.accept(Unknown Source)
[cobertura-instrument]  at org.objectweb.asm.ClassReader.accept(Unknown Source)
[cobertura-instrument]  at org.objectweb.asm.ClassWriter.toByteArray(Unknown Source)
[cobertura-instrument]  at net.sourceforge.cobertura.instrument.Main.addInstrumentationToSingleClass(Main.java:392)
[cobertura-instrument]  at net.sourceforge.cobertura.instrument.Main.addInstrumentation(Main.java:416)
[cobertura-instrument]  at net.sourceforge.cobertura.instrument.Main.parseArguments(Main.java:492)
[cobertura-instrument]  at net.sourceforge.cobertura.instrument.Main.main(Main.java:514)
[cobertura-instrument] Caused by: java.lang.ClassNotFoundException: WarningNode
[cobertura-instrument]  at java.net.URLClassLoader$1.run(URLClassLoader.java:217)
[cobertura-instrument]  at java.security.AccessController.doPrivileged(Native Method)
[cobertura-instrument]  at java.net.URLClassLoader.findClass(URLClassLoader.java:205)
[cobertura-instrument]  at java.lang.ClassLoader.loadClass(ClassLoader.java:323)
[cobertura-instrument]  at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:294)
[cobertura-instrument]  at java.lang.ClassLoader.loadClass(ClassLoader.java:268)
[cobertura-instrument]  at java.lang.Class.forName0(Native Method)
[cobertura-instrument]  at java.lang.Class.forName(Class.java:190)
[cobertura-instrument]  ... 12 more
[cobertura-instrument] Cobertura: Saved information on 19277 classes.
[cobertura-instrument] Instrument time: 17997ms

BUILD FAILED

Solution:
<cobertura-instrument todir="${instrumented.dir}">
        <ignore regex="org.apache.log4j.*" />
        <fileset dir="${project_home}/ext-path">
      <include name="**/*.class" />
       <exclude name="**/*Test.class" />
</fileset>
</cobertura-instrument>


Issue:JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java

XXXXNotFoundException: No result for the given query at SearchService.searchUnique(DefaultSearchService.java:243) at sun.reflect.GeneratedMethodAccessor2047.invoke(Unknown Source) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:622) at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:309) at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:196) at com.sun.proxy.$Proxy30.getXXXX(Unknown Source) at CLSName.getXXXXX(CLSName.java:221) at PoolableThread.run(PoolableThread.java:198)

Solution:
<cobertura-instrument todir="${instrumented.dir}">
        <ignore regex="org.apache.log4j.*" />
        <fileset dir="${prj_home}/ext">
      <include name="**/*.class" />
       <exclude name="**/*Test.class" />
</fileset>
</cobertura-instrument>

Issue While using the Cobertura version 2.1.1:
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'defaultService' defined in class path resource [test-spring.xml]: Cannot resolve reference to bean 'TestDao' while setting bean property 'TestDao'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'TestDao': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private TestService DefaultDao.SearchService; nested exception is org.springframework.beans.factory.CannotLoadBeanClassException: Error loading class  or dependent class; nested exception is java.lang.NoClassDefFoundError: net/sourceforge/cobertura/coveragedata/HasBeenInstrumented
at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveReference(BeanDefinitionValueResolver.java:328)
at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveValueIfNecessary(BeanDefinitionValueResolver.java:106)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyPropertyValues(AbstractAutowireCapableBeanFactory.java:1325)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1086)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:517)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:456)
at org.springframework.beans.factory.support.AbstractBeanFactory$2.getObject(AbstractBeanFactory.java:329)
at de.hybris.platform.spring.ThreadSafeScopeMap.get(ThreadSafeScopeMap.java:68)

Solution: Looking into...


Unable to instrument jar file, as while doing removing the original file:

 [tutorialbyexample]$ ant Buildfile: /tutorialbyexample/build.xml init:
 [delete] Deleting directory /tutorialbyexample/instrumented
 [delete] Deleting directory /tutorialbyexample/htmlReports
 [delete] Deleting: /tutorialbyexample/cobertura.ser
 [mkdir] Created dir: /tutorialbyexample/instrumented
 [mkdir] Created dir: /tutorialbyexample/htmlReports InstrumentEARLib:
 [cobertura-instrument] Cobertura 1.9.4.1 - GNU GPL License (NO WARRANTY) - See  COPYRIGHT file
 [cobertura-instrument] Instrumenting 316 files to /tutorialbyexample/classes [cobertura-instrument]  Cobertura: Saved information on 316 classes.
 [cobertura-instrument] Instrument time: 782ms
 [cobertura-instrument] Cobertura 1.9.4.1 - GNU GPL License (NO WARRANTY) - See  COPYRIGHT file
 [cobertura-instrument] Cobertura: Loaded information on 316 classes.
 [cobertura-instrument] Instrumenting 1 file to /tutorialbyexample/web/webroot/WEB-INF/classes  [cobertura-instrument] Cobertura: Saved information on 317 classes.
 [cobertura-instrument] Instrument time: 192ms
 [cobertura-instrument] Cobertura 1.9.4.1 - GNU GPL License (NO WARRANTY) - See  COPYRIGHT file [cobertura-instrument] Cobertura: Loaded information on 317 classes.
[cobertura-instrument] Instrumenting 1 file to /tutorialbyexample/bin
[cobertura-instrument] Cobertura: Error closing output stream.
[cobertura-instrument] java.util.zip.ZipException: ZIP file must have at least one entry [cobertura-instrument] at java.util.zip.ZipOutputStream.finish(ZipOutputStream.java:321)
[cobertura-instrument] at java.util.zip.DeflaterOutputStream.close(DeflaterOutputStream.java:163) [cobertura-instrument] at java.util.zip.ZipOutputStream.close(ZipOutputStream.java:338)
[cobertura-instrument] at net.sourceforge.cobertura.util.IOUtil.closeOutputStream(IOUtil.java:165) [cobertura-instrument] at net.sourceforge.cobertura.instrument.Main.addInstrumentationToArchive(Main.java:319) [cobertura-instrument] at net.sourceforge.cobertura.instrument.Main.parseArguments(Main.java:488) [cobertura-instrument] at net.sourceforge.cobertura.instrument.Main.main(Main.java:514) [cobertura-instrument] Cobertura: Saved information on 317 classes.
[cobertura-instrument] Instrument time: 188ms BUILD SUCCESSFUL Total time: 4 seconds Issue cobertura-1.9.4.1: nested exception is java.lang.NoClassDefFoundError: net/sourceforge/cobertura/coveragedata/HasBeenInstrumented Solution: Copy the below jars in tomcat/lib cobertura-1.9.4.1/cobertura.jar cobertura-1.9.4.1/lib/asm-3.0.jar cobertura-1.9.4.1/lib/jakarta-oro-2.0.8.jar cobertura-1.9.4.1/lib/log4j-1.2.9.jar cobertura-1.9.4.1/lib/asm-tree-3.0.jar Restart the tomcat server.

3 comments:

  1. Same issue i was facing ... thanks for your post on Cobertura...issue got resolved...

    ReplyDelete
  2. This comment has been removed by the author.

    ReplyDelete
  3. Hi,
    I am getting the following exception while running the cobertura instrumented war. Please help.
    Below is the error log for details.

    org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'applicationStartupInterceptor' defined in ServletContext resource [/WEB-INF/xanitewebclient-core-servlet.xml]: Instantiation of bean failed; nested exception is java.lang.NoClassDefFoundError: peterevans/xanite/common/utils/UtilityService
    org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:451)
    org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:249)
    org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:155)
    org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:246)
    org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:160)
    org.springframework.beans.factory.support.DefaultListableBeanFactory.getBeansOfType(DefaultListableBeanFactory.java:248)
    org.springframework.context.support.AbstractApplicationContext.getBeansOfType(AbstractApplicationContext.java:820)
    org.springframework.context.support.AbstractApplicationContext.registerListeners(AbstractApplicationContext.java:597)
    org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:349)
    org.springframework.web.servlet.FrameworkServlet.createWebApplicationContext(FrameworkServlet.java:332)
    org.springframework.web.servlet.FrameworkServlet.initWebApplicationContext(FrameworkServlet.java:266)
    org.springframework.web.servlet.FrameworkServlet.initServletBean(FrameworkServlet.java:236)
    org.springframework.web.servlet.HttpServletBean.init(HttpServletBean.java:126)
    javax.servlet.GenericServlet.init(GenericServlet.java:160)
    org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:472)
    org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:99)
    org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:936)
    org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:407)
    org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1004)
    org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:589)
    org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:312)
    java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)
    java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
    java.lang.Thread.run(Thread.java:662)

    ReplyDelete

Please provide your input, it will honer for me...