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

StackOverflow https://stackoverflow.com/questions/17522385

  •  02-06-2022
  •  | 
  •  

Domanda

I get following exception with new cobertura (2.0.2..). I guess it is some how related to new object creation 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.

The following is the code related to 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 un-comment the code block some dummy statements , then instrumentation works fine. Has any one seen this? Any potential fixes?

Edit: Error occurs with java6 and java7.

È stato utile?

Soluzione 2

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

Your test case may be useful to debug the issue...

Altri suggerimenti

Original problem was due to a Cobertura defect. It is not fixed. Cobertura now supports an additional argument for auxillary classpath.. This will be used to resolve any classes required for instrumentation.

cobertura-ant task documentation

Adding auxClasspath

auxClasspath argument is designed to remove the ClassNotFoundException during instrumentation. See https://github.com/cobertura/cobertura/wiki/FAQ#classnotfoundexception-during-instrumentation for more information on this argument

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

"This is because during instrumentation in cobertura 2.0, we use ASM to rebuild the .class files. We rebuild the stackmap which is a requirement to be compatible with java 7 and anything after. This does not mean that we recompile the code, however ASM requires that we provide the binaries of the other classes just in case it needs to look up any super methods. To fix this we use an argument called auxClasspath."

Adding the following code to your ant file (build.xml) should resolve the issue.

<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>

This worked for me.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top