0

I have a webapp comprised of a bunch of OSGI bundles. The requirement is to generate the cobertura code coverage report when running automation tests on the deployed artifact. For this I have instrumented the deployable artifact using cobertura as mentioned here Performed all the required setup and was able to generate the instrumented classes and corresponding deployable artifact ".war". and deployed it successfully in wildfly. However, after accessing the application and performing few operations for capturing the coverage, Tried stopping the server (the jboss shutdown hook would call the required cobertura class and generate the cobertura.ser file which is used to create the coverage report) and this results in the below exception

2015-02-09 17:46:06,420 SEVERE [net.sourceforge.cobertura.coveragedata.TouchCollector] (Thread-84) Cannot apply touches: java.lang.NoSuchMethodException: com.sample.package.SomeInstrumentedClass.__cobertura_classmap(net.sourceforge.cobertura.coveragedata.LightClassmapListener)
at java.lang.Class.getDeclaredMethod(Class.java:1994) [rt.jar:1.7.0_25]
at net.sourceforge.cobertura.coveragedata.TouchCollector.applyTouchesToSingleClassOnProjectData(TouchCollector.java:125) [admin-rest-api-1.0.0.jar:1.0.0]
at net.sourceforge.cobertura.coveragedata.TouchCollector.applyTouchesOnProjectData(TouchCollector.java:107) [admin-rest-api-1.0.0.jar:1.0.0]
at net.sourceforge.cobertura.coveragedata.ProjectData.saveGlobalProjectData(ProjectData.java:270) [admin-rest-api-1.0.0.jar:1.0.0]
at net.sourceforge.cobertura.coveragedata.SaveTimer.run(SaveTimer.java:32) [admin-rest-api-1.0.0.jar:1.0.0]
at java.lang.Thread.run(Thread.java:724) [rt.jar:1.7.0_25]

This exception is thrown for all the classes cobertura is trying to access. When I unpack the deployed artifact, I can see all the classes instrumented with cobertura specific code and the specific method __cobertura_classmap present in all the instrumented classes. Not able to figure out as to why NoSuchMethodException is thrown inspite of the method actually being present in the deployed artifact.

I am using cobertura-2.0.3, cobertura-maven-plugin-2.6 and java version 1.7.0_71 and Apache Felix

Have anyone encountered this issue? Does OSGI has anything to do with this behavior?

Alessandro Da Rugna
  • 4,571
  • 20
  • 40
  • 64
Sampath
  • 41
  • 2
  • If you could upload your example to somewhere, that could help a lot. Based on this information it is hard to find out, how you use Felix withing your environment. – Balazs Zsoldos Feb 10 '15 at 12:52

1 Answers1

0

I had the same issue with Cobertura 2.1.1, Java 1.8.0_72 & Java 1.7.0_79, where the instrumented classes did contain the method that it was complaining about.

I fixed this Cobertura issue in my project by moving my inner classes (which extended the one that Cobertura complained about) from being inside my unit test class to being in its own class file.

I also had to move one of my variables out of the problematic class to being a standalone class. The variable used to be a Gson TypeToken:

com.google.gson.reflect.TypeToken GSON_TYPE_TOKEN = new TypeToken<MyJsonStructure>(){};

So my suggestion would be to try and avoid inner classes.

Chris
  • 81
  • 1
  • 5