Java.lang.RuntimeException: java.lang.ClassNotFoundException: <org.objectweb.asm.ClassWriter.getCommonSuperClass (Unknown source)>

I get the following exception with new cobertura (2.0.2 ..) . I assume that some of them are associated with the creation of a new object immediately in a new block.

WARN instrumentClass, Unable to instrument file c:\apps\ijprojects\TrickyInstrument\out\production\TrickyInstrument\InstrumentationFailsOnFirstNewClassInTryBlock.class java.lang.RuntimeException: java.lang.ClassNotFoundException: DataAccess at org.objectweb.asm.ClassWriter.getCommonSuperClass(Unknown Source) at org.objectweb.asm.ClassWriter.a(Unknown Source) at org.objectweb.asm.Frame.a(Unknown Source) at org.objectweb.asm.Frame.a(Unknown Source) at org.objectweb.asm.MethodWriter.visitMaxs(Unknown Source) at org.objectweb.asm.MethodVisitor.visitMaxs(Unknown Source) at org.objectweb.asm.util.CheckMethodAdapter.visitMaxs(Unknown Source) at org.objectweb.asm.MethodVisitor.visitMaxs(Unknown Source) at org.objectweb.asm.commons.LocalVariablesSorter.visitMaxs(Unknown Source) at org.objectweb.asm.tree.MethodNode.accept(Unknown Source) at org.objectweb.asm.util.CheckMethodAdapter$1.visitEnd(Unknown Source) at org.objectweb.asm.MethodVisitor.visitEnd(Unknown Source) at org.objectweb.asm.util.CheckMethodAdapter.visitEnd(Unknown Source) at org.objectweb.asm.ClassReader.b(Unknown Source) at org.objectweb.asm.ClassReader.accept(Unknown Source) at org.objectweb.asm.ClassReader.accept(Unknown Source) at net.sourceforge.cobertura.instrument.CoberturaInstrumenter.instrumentClass(CoberturaInstrumenter.java:204) at net.sourceforge.cobertura.instrument.CoberturaInstrumenter.instrumentClass(CoberturaInstrumenter.java:121) at net.sourceforge.cobertura.instrument.CoberturaInstrumenter.addInstrumentationToSingleClass(CoberturaInstrumenter.java:233) at net.sourceforge.cobertura.instrument.Main.addInstrumentationToSingleClass(Main.java:274) at net.sourceforge.cobertura.instrument.Main.addInstrumentation(Main.java:283) at net.sourceforge.cobertura.instrument.Main.addInstrumentation(Main.java:292) at net.sourceforge.cobertura.instrument.Main.parseArguments(Main.java:373) at net.sourceforge.cobertura.instrument.Main.main(Main.java:395) 8 Jul, 2013 2:05:07 PM net.sourceforge.cobertura.coveragedata.CoverageDataFileHandler saveCoverageData INFO: Cobertura: Saved information on 2 classes. 

Below is the code associated with the above exception.

 public class InstrumentationFailsOnFirstNewClassInTryBlock { public void saveToDatabase() { // try { // boolean b=false; // if ( b) { // System.out.println("no action"); // } DataAccess da = new DataAccess(); System.out.println("nothing"); } catch (Exception e) { } } } class DataAccess { public DataAccess() { //To change body of created methods use File | Settings | File Templates. } } 

If I do not comment on the code block with some fictitious statements, then the toolkit works fine. Has anyone seen this? Any potential fixes?

Edit: An error occurs with java6 and java7.

+4
source share
3 answers

I had a similar problem and it could be a bug, see: https://github.com/cobertura/cobertura/issues/49

Your test case may be useful for debugging a problem ...

+1
source

The original problem was caused by a defect in Cobertura. It is not fixed. Cobertura now supports an optional argument to the auxillary classpath. . This will be used to resolve any classes required for the hardware.

coprocessor documentation ant

Adding auxClasspath

The auxClasspath argument is for removing a ClassNotFoundException during hardware. See https://github.com/cobertura/cobertura/wiki/FAQ#classnotfoundexception-during-instrumentation for more information about this argument

+2
source

From https://github.com/cobertura/cobertura/wiki/FAQ#classnotfoundexception-during-instrumentation :

"This is because during the tooling in cobertura 2.0 we use ASM to restore .class files. We rebuild the stack, which is required for compatibility with and after java 7. This does not mean that we recompile the code, but ASM requires so that we provide binaries of other classes just in case he needs to look for any super methods. To fix this, we use an argument called auxClasspath. "

Adding the following code to your ant file (build.xml) should fix the problem.

 <path id="cobertura.auxpath"> <pathelement location="${bin}"/> </path> <target name="instrument_coverage" depends="init_coverage" description="Instruments source code for coverage measurement"> <cobertura-instrument datafile="${coverage.datafile}"> <fileset refid="coverage-files"/> <auxClasspath> <path refid="cobertura.auxpath" /> </auxClasspath> </cobertura-instrument> </target> 

It worked for me.

+1
source

Source: https://habr.com/ru/post/1490231/


All Articles