【问题标题】:Maven build causes VerifyError with java 1.7Maven 构建使用 java 1.7 导致 VerifyError
【发布时间】:2012-06-07 19:22:36
【问题描述】:

我有一个带有测试用例的简单类,并且在 Eclipse 中一切正常,但是当我运行 maven build 时(目标是:安装 cobertura:cobertura checkstyle:checkstyle-aggregate)我在 surefire 中看到了一个验证错误报告。

这是确切的错误:

-------------------------------------------------------------------------------
Test set: com.diploma.testProject.ClassUnderTestTest
-------------------------------------------------------------------------------
Tests run: 2, Failures: 0, Errors: 2, Skipped: 0, Time elapsed: 0.034 sec <<< FAILURE!
testMethodReturnsTrue(com.diploma.testProject.ClassUnderTestTest)  Time elapsed: 0.005 sec  <<< ERROR!
java.lang.VerifyError: Expecting a stackmap frame at branch target 79 in method com.diploma.testProject.ClassUnderTest.method(II)Z at offset 24
    at com.diploma.testProject.ClassUnderTestTest.testMethodReturnsTrue(ClassUnderTestTest.java:37)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:601)
    at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:44)
    at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)
    at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:41)
    at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:20)
    at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:28)
    at org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:31)
    at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:76)
    at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:50)
    at org.junit.runners.ParentRunner$3.run(ParentRunner.java:193)
    at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:52)
    at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:191)
    at org.junit.runners.ParentRunner.access$000(ParentRunner.java:42)
    at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:184)
    at org.junit.runners.ParentRunner.run(ParentRunner.java:236)
    at org.apache.maven.surefire.junit4.JUnit4TestSet.execute(JUnit4TestSet.java:35)
    at org.apache.maven.surefire.junit4.JUnit4Provider.executeTestSet(JUnit4Provider.java:146)
    at org.apache.maven.surefire.junit4.JUnit4Provider.invoke(JUnit4Provider.java:97)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:601)
    at org.apache.maven.surefire.booter.ProviderFactory$ClassLoaderProxy.invoke(ProviderFactory.java:103)
    at $Proxy0.invoke(Unknown Source)
    at org.apache.maven.surefire.booter.SurefireStarter.invokeProvider(SurefireStarter.java:145)
    at org.apache.maven.surefire.booter.SurefireStarter.runSuitesInProcess(SurefireStarter.java:87)
    at org.apache.maven.surefire.booter.ForkedBooter.main(ForkedBooter.java:69)

testMethodReturnFalse(com.diploma.testProject.ClassUnderTestTest)  Time elapsed: 0 sec  <<< ERROR!
java.lang.VerifyError: Expecting a stackmap frame at branch target 79 in method com.diploma.testProject.ClassUnderTest.method(II)Z at offset 24
    at com.diploma.testProject.ClassUnderTestTest.testMethodReturnFalse(ClassUnderTestTest.java:42)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:601)
    at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:44)
    at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)
    at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:41)
    at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:20)
    at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:28)
    at org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:31)
    at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:76)
    at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:50)
    at org.junit.runners.ParentRunner$3.run(ParentRunner.java:193)
    at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:52)
    at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:191)
    at org.junit.runners.ParentRunner.access$000(ParentRunner.java:42)
    at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:184)
    at org.junit.runners.ParentRunner.run(ParentRunner.java:236)
    at org.apache.maven.surefire.junit4.JUnit4TestSet.execute(JUnit4TestSet.java:35)
    at org.apache.maven.surefire.junit4.JUnit4Provider.executeTestSet(JUnit4Provider.java:146)
    at org.apache.maven.surefire.junit4.JUnit4Provider.invoke(JUnit4Provider.java:97)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:601)
    at org.apache.maven.surefire.booter.ProviderFactory$ClassLoaderProxy.invoke(ProviderFactory.java:103)
    at $Proxy0.invoke(Unknown Source)
    at org.apache.maven.surefire.booter.SurefireStarter.invokeProvider(SurefireStarter.java:145)
    at org.apache.maven.surefire.booter.SurefireStarter.runSuitesInProcess(SurefireStarter.java:87)
    at org.apache.maven.surefire.booter.ForkedBooter.main(ForkedBooter.java:69)

这是课程:

public class ClassUnderTest {
    public static boolean method(int a, int b) {
        if ( a == b) {
            System.out.println("");
            return true;
        } 
        return false;
    }
}

还有测试:

public class ClassUnderTestTest {

    @Test
    public void testMethodReturnsTrue() {
        assertTrue(ClassUnderTest.method(1, 1));
    }

    @Test
    public void testMethodReturnFalse() throws Exception {
        assertFalse(ClassUnderTest.method(1, 2));
    }

}

还有 pom.xml :

<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.diploma</groupId>
  <artifactId>testProject</artifactId>
  <version>0.0.1-SNAPSHOT</version>
  <packaging>jar</packaging>

  <name>testProject</name>
  <url>http://maven.apache.org</url>

  <properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
  </properties>

  <dependencies>
    <dependency>
      <groupId>junit</groupId>
      <artifactId>junit</artifactId>
      <version>4.10</version>
      <scope>test</scope>
    </dependency>
  </dependencies>

  <build>
    <pluginManagement>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>2.4</version>
                <configuration>
                    <source>1.7</source>
                    <target>1.7</target>
                    <testSource>1.7</testSource>
                    <testTarget>1.7</testTarget>
                </configuration>
            </plugin>
        </plugins>
    </pluginManagement>
  </build>
</project>

将目标设置为 1.5 时,这是可行的,但我需要它与 1.7 一起使用。 更奇怪的是,将方法修改为只有一个这样的返回:

public class ClassUnderTest {
    public static boolean method(int a, int b) {
        if ( a == b) {
            System.out.println("");
        } 
        return false;
    }
}

也解决了这个问题。 我试过在 pom 的属性块中设置目标和源版本,但结果是一样的。

有没有办法让它在 1.7 版上运行?

编辑:这个问题也只出现在目标 cobertura:cobertura。

【问题讨论】:

标签: java maven junit cobertura verifyerror


【解决方案1】:

问题似乎出在 cobertura。看起来它不支持java 1.7 很好。 该修复类似于@Raghuram 为 Eclipse 编写的链接。 像这样修改 pom 可以使测试正常工作:

    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-surefire-plugin</artifactId>
                <version>2.12</version>
                <configuration>
                    <argLine>-XX:-UseSplitVerifier</argLine>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>2.4</version>
                <configuration>
                    <source>1.7</source>
                    <target>1.7</target>
                    <testSource>1.7</testSource>
                    <testTarget>1.7</testTarget>
                </configuration>
            </plugin>
        </plugins>
    </build>

【讨论】:

  • 类似的设置适用于 buildr:ENV['JAVA_OPTS'] ||= "-XX:UseSplitVerifier"
【解决方案2】:

编辑:mvn cobertura:cobertura 由于缺乏对 Java 7 的 cobertura 支持而无法工作。This SO question 对此进行了讨论。看起来JaCoCo 是要走的路。

mvn install 在 Windows 7 上使用 maven-3.0.4java 1.7.0_04 的命令行对我来说可以正常工作。可能您正在点击 this eclipse bug

要添加到@Pau' 的答案,&lt;pluginManagement&gt; 用于多模块 pom 以声明可以根据孩子的要求继承的 &lt;plugin&gt; 元素。

问题中的pom 以及以下sn-p 没有错误:

<build>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-compiler-plugin</artifactId>
            <version>2.4</version>
            <configuration>
                <source>1.7</source>
                <target>1.7</target>
                <testSource>1.7</testSource>
                <testTarget>1.7</testTarget>
            </configuration>
        </plugin>
    </plugins>

【讨论】:

  • 嗯.. 我也从命令行得到了同样的错误,但现在我发现它来自目标 cobertura:cobertura。运行时仅安装工作正常。感谢您提供关于 的说明
  • @ZhivkoDelchev。我得到与cobertura 相同的错误。更新了答案
  • Cobertura 2.x 是新的,声称支持 java 7。
  • 具体> 2.5,所以2.6及以上@Dzhaughn。
猜你喜欢
  • 2019-11-09
  • 1970-01-01
  • 1970-01-01
  • 2018-08-28
  • 2018-12-08
  • 2017-03-23
  • 2013-11-24
  • 2015-01-22
相关资源
最近更新 更多