Creating Maven raises VerifyError with java 1.7

I have one simple class with a test case for it, and everything works fine in eclipse, but when I run maven build (with the following objectives: install cobertura: cobertura checkstyle: checkstyle-aggregate), I see a Verify error in the surefire report.

Here is the exact error:

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

This is the class:

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

And the test:

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

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

When setting the target to 1.5, this works, but I need it to work from 1.7. More strange is that only one return is required to modify a method:

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

also fixes the problem. I tried to set the target and source version in the pom property block, but the result was the same.

Is there a way to do this in version 1.7?

EDIT: Also, this problem only occurs with the goal of cobertura: cobertura.

+6
source share
2 answers

The problem seems to be in cobertur. It doesn't seem to support java 1.7 very well. The fix was like a link that @Raghuram wrote for an eclipse. By modifying pom, how this makes the test work fine:

  <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> 
+20
source

Edit: mvn cobertura:cobertura does not work due to lack of cobertura support for Java 7. This SO question discusses this. JaCoCo seems to be the way to go.

mvn install works fine for me from the command line with maven-3.0.4 and java 1.7.0_04 on Windows 7. Perhaps you are pushing this Eclipse error ?

To add @Pau to the answer, <pluginManagement> used in multi-module poms to declare <plugin> elements that can be inherited according to the requirements of child elements.

I am not getting errors with pom in the question, as well as the following snippet:

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

+4
source

Source: https://habr.com/ru/post/917285/


All Articles