本文介绍了在JDK 1.7上使用emma/Cobertura时出现java.lang.VerifyError的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当尝试使用Apache Buildr创建构建时,我面临下面链接中提到的完全相同的问题.

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

Testng,Emma,Cobertura ,覆盖率和JDK 7导致ClassFormatError和VerifyError

我在测试工件时尝试使用-XX:-UseSplitVerifier选项(如下所示),但这不能解决我的问题.

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'])

错误:

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

更新-解决方案/根本原因.

使用Java 1.7编译的代码需要堆栈映射框架指令.如果要修改Java 1.7类文件,则需要使用ClassWriter.COMPUTE_FRAMES或MethodVisit.visitFrame().

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

我刚刚将Cobertura添加到Java 7项目中,并对我的单元测试因以下原因而失败感到失望:

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

看起来cobertura的字节码检测工具与Java 7不兼容.Java7更改了类格式,增加了用于验证的堆栈映射,而cobertura尚未赶上....他们似乎已经更新了代码并立即将其提交给母版.

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

如何解决此错误?

Oracle确实通过使用-XX:UseSplitVerifier VM选项提供了解决该问题的方法.

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"

对于Maven:

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

对于Gradle:

test
 {
  jvmArgs
"-XX:-UseSplitVerifier"

.....

推荐答案

Buildr运行嵌入式JVM(通常在不使用JRuby时使用Ruby-Java Bridge(RJB))并从该JVM中执行测试选择,所以我建议在启动buildr之前,还要通过JAVA_OPTIONS传递禁用验证的选项:

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

这篇关于在JDK 1.7上使用emma/Cobertura时出现java.lang.VerifyError的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-24 14:22
查看更多