java.lang.VerifyError when using emma / Cobertura on JDK 1.7

拟墨画扇 提交于 2019-12-23 15:21:47

问题


I am facing the exact same issue mentioned in the link below when trying to create a build using Apache Buildr.

Testng, Emma, Cobertura, coverage and JDK 7 result in ClassFormatError and VerifyError

I tried using the -XX:-UseSplitVerifier option(as below) when testing the artifacts but that doesn't resolve my issue.

  test.using( :java_args => ['-ea','-XX:-UseSplitVerifier'])

Error:

Instrumenting classes with emma metadata file /test-client/reports/emma/coverage.em
JavaTestFilter: Unable to load class com.test.activemq.QueueConsumerTest to determine testing ability

Update - Solution / Root cause..

Code compiled using Java 1.7 requires stack map frame instructions. If you wish to modify Java 1.7 class files, you need to use ClassWriter.COMPUTE_FRAMES or MethodVisit.visitFrame().

java.lang.VerifyError - Java 7 and Cobertura

I just added Cobertura to a Java 7 project and was disappointed that my unit tests started failing with:

 java.lang.VerifyError: Expecting a stackmap frame at branch target blah... 

Looks like cobertura's byte code instrumentation is not compatible with Java 7. Java 7 changed the class format with the addition of a stack map used for verification and cobertura hasn't caught up yet.... They seem to have updated the code and committed it to master now..

https://github.com/cobertura/cobertura/pull/6

How to fix this error?

Oracle does provide a way around the problem by using the -XX:UseSplitVerifier VM option.

Apache Buildr:

ENV['JAVA_OPTS'] ||= "-XX:UseSplitVerifier"

OR

ENV['JAVA_OPTS'] ||= "-Xverify:none"

For Maven:

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-surefire-plugin</artifactId>
    <version>2.12</version>
    <configuration>
        <argLine>-XX:-UseSplitVerifier</argLine>
    </configuration>
</plugin>

For Gradle:

test
 {     
  jvmArgs
"-XX:-UseSplitVerifier"

.....


回答1:


Buildr runs an embedded JVM (typically using the Ruby-Java Bridge (RJB) when not using JRuby) and performs test selection from within that JVM so I would suggest also passing your verification-disabling options through JAVA_OPTIONS before launching buildr:

$ export JAVA_OPTIONS="-Xverify:none"  # or other verification-disabling options


来源:https://stackoverflow.com/questions/16905947/java-lang-verifyerror-when-using-emma-cobertura-on-jdk-1-7

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!