Code coverage: in standalone mode can get TestRun$1 class missing #233

Closed
wknorr opened this Issue Oct 30, 2015 · 2 comments

Projects

None yet

3 participants

@wknorr
wknorr commented Oct 30, 2015

Summary
When running the code coverage tool in standalone mode, for some applications I get an error saying mockit/internal/state/TestRun$1 cannot be found.

It quite possibly is related to two classes referencing each other.

Code coverage is still generated but I believe the classes that caused the error do not get any data associated with them.

If I add the following to the coverage/pom.xml file it takes care of the error, but I assume these files are not meant to be needed:

               <include>mockit/internal/state/TestRun$1.class</include>
               <include>mockit/internal/state/ExecutingTest.class</include>
               <include>mockit/internal/state/ExecutingTest$1.class</include>
               <include>mockit/internal/state/CascadingTypes.class</include>
               <include>mockit/internal/state/MockClasses.class</include>
               <include>mockit/MockUp.class</include>
               <include>mockit/internal/util/FieldReflection.class</include>
               <include>mockit/internal/mockups/MockStates.class</include>

Also, strangely, if I compile my project with a target of 1.6, I do not get the error. (With 1.7 or 1.8 I do.) i.e.

        <maven.compiler.source>1.6</maven.compiler.source>
        <maven.compiler.target>1.6</maven.compiler.target>

Steps to reproduce

  1. Compile the project: "mvn install".
  2. Run the application from the command line with the following command (with the paths corrected to match your own system):
    "C:\Program Files\Java\jdk1.8.0_60\bin\java.exe" -classpath ./target/TestApp-1.0-SNAPSHOT.jar -javaagent:C\jmockit121\jmockit1-master\coverage\target\jmockit-coverage-1.21.jar -Dcoverage-outputDir=./CodeCoverageReports -Dcoverage-classes=com.qhrtech.emr.qa.* -Dcoverage-metrics=line -Dcoverage-output=html-nocp com.qhrtech.emr.qa.testapp.TestApp

*The error is printed to the console immediately.

Versions
jmockit-coverage: 1.21 (GitHub 4e9bdf3) (compiled from source as per the instructions on GitHub)
Maven: 3.3.3
Java: JDK 1.8.0 u60

Stack trace

 [java] java.lang.NoClassDefFoundError: mockit/internal/state/TestRun$1
 [java]     at mockit.internal.util.ClassLoad.loadClass(ClassLoad.java:49)
 [java]     at mockit.internal.util.ClassLoad.loadByInternalName(ClassLoad.java:31)
 [java]     at mockit.internal.util.ClassLoad.getSuperClass(ClassLoad.java:146)
 [java]     at mockit.internal.util.ClassLoad.actualSuperClass(ClassLoad.java:177)
 [java]     at mockit.internal.util.ClassLoad.whichIsSuperClass(ClassLoad.java:161)
 [java]     at mockit.external.asm.ClassWriter.getCommonSuperClass(ClassWriter.java:1694)
 [java]     at mockit.external.asm.ClassWriter.getMergedType(ClassWriter.java:1661)
 [java]     at mockit.external.asm.Frame.merge(Frame.java:1426)
 [java]     at mockit.external.asm.Frame.merge(Frame.java:1325)
 [java]     at mockit.external.asm.MethodWriter.visitMaxs(MethodWriter.java:1475)
 [java]     at mockit.external.asm.MethodVisitor.visitMaxs(MethodVisitor.java:804)
 [java]     at mockit.external.asm.ClassReader.readCode(ClassReader.java:1554)
 [java]     at mockit.external.asm.ClassReader.readMethod(ClassReader.java:1017)
 [java]     at mockit.external.asm.ClassReader.accept(ClassReader.java:693)
 [java]     at mockit.external.asm.ClassReader.accept(ClassReader.java:506)
 [java]     at mockit.coverage.modification.ClassModification.modifyClassForCoverage(ClassModification.java:142)
 [java]     at mockit.coverage.modification.ClassModification.modifyClassForCoverage(ClassModification.java:217)
 [java]     at mockit.coverage.modification.ClassModification.modifyClass(ClassModification.java:192)
 [java]     at mockit.coverage.CodeCoverage.transform(CodeCoverage.java:127)
 [java]     at sun.instrument.TransformerManager.transform(TransformerManager.java:188)
 [java]     at sun.instrument.InstrumentationImpl.transform(InstrumentationImpl.java:428)
 [java]     at java.lang.ClassLoader.defineClass1(Native Method)
 [java]     at java.lang.ClassLoader.defineClass(ClassLoader.java:760)
 [java]     at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)
 [java]     at java.net.URLClassLoader.defineClass(URLClassLoader.java:467)
 [java]     at java.net.URLClassLoader.access$100(URLClassLoader.java:73)
 [java]     at java.net.URLClassLoader$1.run(URLClassLoader.java:368)
 [java]     at java.net.URLClassLoader$1.run(URLClassLoader.java:362)
 [java]     at java.security.AccessController.doPrivileged(Native Method)
 [java]     at java.net.URLClassLoader.findClass(URLClassLoader.java:361)
 [java]     at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
 [java]     at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:331)
 [java]     at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
 [java]     at com.qhrtech.emr.qa.testapp.TestApp.main(TestApp.java:15)
 [java] Caused by: java.lang.ClassNotFoundException: mockit.internal.state.TestRun$1
 [java]     at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
 [java]     at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
 [java]     at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:331)
 [java]     at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
 [java]     ... 34 more
 [java] JMockit: Coverage report written to C:\QA\SVNWorkingCopy\accuro-2015.03\TestApp\CodeCoverageReports

Source Code
I have used a simplified application with three classes.
===TestApp.java===

package com.qhrtech.emr.qa.testapp;

import java.util.Scanner

public class TestApp {

    public static void main( String[] args ) {

        System.out.println( "Press enter." );

        UserManager um = new UserManager();

        Scanner keyboard = new Scanner( System.in );
        keyboard.nextLine();

    }

}

===UserManager.java===

package com.qhrtech.emr.qa.testapp;

public class UserManager {

    public void checkPassword() {
        try {
            PasswordManager pm = new PasswordManager();
        } catch ( IllegalStateException e ) {
            System.err.println( "Problem." );
        }
    }

    public static String getImportantUser() {
        return "Bob";
    }

}

===PasswordManager.java===

package com.qhrtech.emr.qa.testapp;

public class PasswordManager {

    public PasswordManager() {

        String bestUser;
        bestUser = UserManager.getImportantUser();

    }

}

===pom.xml===

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <groupId>com.qhrtech.emr.qa</groupId>
    <artifactId>TestApp</artifactId>
    <version>1.0-SNAPSHOT</version>
    <packaging>jar</packaging>
    <dependencies>
        <dependency>
            <groupId>org.slf4j</groupId>
            <artifactId>jcl-over-slf4j</artifactId>
            <version>1.6.6</version>
        </dependency>
    </dependencies>
    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <maven.compiler.source>1.7</maven.compiler.source>
        <maven.compiler.target>1.7</maven.compiler.target>
    </properties>

</project>
@rliesenfeld rliesenfeld added the bug label Oct 30, 2015
@rliesenfeld rliesenfeld self-assigned this Oct 30, 2015
@rliesenfeld
Member

Thanks! TestRun$1.class is needed, but is indeed missing from jmockit-coverage.jar.

@alexanderjohn

I am also receiving this issue. Will this be fixed in the 1.21 release on Dec 27?

@rliesenfeld rliesenfeld added a commit that closed this issue Dec 27, 2015
@rliesenfeld rliesenfeld Temporary addition of extra classes from main module to coverage modu…
…le, to avoid NoClassDefFoundErrors when on standalone mode; closes #233.
55fc60b
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment