I'm using powermock in my code base for quite a while. After minor modification to the code, I'm getting this error when running "mvn clean install". I'm wondering how to investigate an drill down this issue.
java.lang.VerifyError: Expecting a stackmap frame at branch target 17
Exception Details:
Location:
org/neo4j/jdbc/Driver.createExecutor(Ljava/lang/String;Ljava/util/Properties;)Lorg/neo4j/jdbc/QueryExecutor; @4: ifnonnull
Reason:
Expected stackmap frame at this location.
Bytecode:
0000000: 2ab4 0024 c700 0dbb 00b3 5912 b5b7 00b8
0000010: bf2a b400 242b 2cb9 00ba 0300 b0
Java 7 introduced a stricter verification and changed the class format a bit -- to contain a stack map, used to verify that code is correct. The exception you see, means that some method doesn't have a valid stack map.
Java version or bytecode instrumentation could both be to blame. Usually this means that a library that the application uses, generates invalid bytecode that doesn't pass the stricter verification. So nothing else than reporting it as a bug to the library can be done by the developer.
We had the similar issue #375. PowerMock uses Javassist to generate byte code, so you may try to use latest version of Javassist. Also you may downgrade your JDK to 1.6 where verification disabled. Or disable it with using JVM parameter -noverify.
@thekingnothing, I'm using powermock 1.5.5 and javassist 3.18.2-GA, but still I'm getting the same error.
Any idea why it's failing or how we can fix this? We don't want to use -noverify.
@risha8h if you're using gradle
add lines below to your build.gradle - should do the trick
test {
jvmArgs "-noverify"
}
java.lang.VerifyError: Expecting a stackmap frame at branch target 95
Exception Details:
Location:
com/paypal/report/paymentinfo/bl/impl/XYZ.
Reason:
Expected stackmap frame at this location.
Bytecode:
0000000: 2ab7 0001 2a00 0000 0001 4c01 4d13 0195
0000010: b801 9803 bd00 2213 019a b801 9cb8 01a0
0000020: 4e2d b201 a2a5 003a 2dc1 01a4 9900 2bb8
0000030: 01aa 1301 abb8 01ad 1301 afb8 01b4 a700
0000040: 07b8 01bc bf01 b601 c0b6 01c4 01b6 01c9
0000050: c000 024d a700 082d c000 024d a700 0bbb
0000060: 0002 59b7 01cb 4d2c b500 04b1
Exception Handler Table:
bci [56, 62] => handler: 65
at java.lang.Class.getDeclaredMethods0(Native Method)
at java.lang.Class.privateGetDeclaredMethods(Class.java:2531)
at java.lang.Class.privateGetPublicMethods(Class.java:2651)
at java.lang.Class.getMethods(Class.java:1467)
at org.powermock.modules.junit4.internal.impl.PowerMockJUnit44RunnerDelegateImpl.getTestMethods(PowerMockJUnit44RunnerDelegateImpl.java:95)
at org.powermock.modules.junit4.internal.impl.PowerMockJUnit44RunnerDelegateImpl.<init>(PowerMockJUnit44RunnerDelegateImpl.java:71)
at org.powermock.modules.junit4.internal.impl.PowerMockJUnit47RunnerDelegateImpl.<init>(PowerMockJUnit47RunnerDelegateImpl.java:42)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:526)
at org.powermock.modules.junit4.common.internal.impl.JUnit4TestSuiteChunkerImpl.createDelegatorFromClassloader(JUnit4TestSuiteChunkerImpl.java:144)
at org.powermock.modules.junit4.common.internal.impl.JUnit4TestSuiteChunkerImpl.createDelegatorFromClassloader(JUnit4TestSuiteChunkerImpl.java:39)
at org.powermock.tests.utils.impl.AbstractTestSuiteChunkerImpl.createTestDelegators(AbstractTestSuiteChunkerImpl.java:217)
at org.powermock.modules.junit4.common.internal.impl.JUnit4TestSuiteChunkerImpl.<init>(JUnit4TestSuiteChunkerImpl.java:59)
at org.powermock.modules.junit4.common.internal.impl.AbstractCommonPowerMockRunner.<init>(AbstractCommonPowerMockRunner.java:32)
at org.powermock.modules.junit4.PowerMockRunner.<init>(PowerMockRunner.java:31)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:526)
at org.junit.internal.builders.AnnotatedBuilder.buildRunner(AnnotatedBuilder.java:31)
at org.junit.internal.builders.AnnotatedBuilder.runnerForClass(AnnotatedBuilder.java:24)
at org.junit.runners.model.RunnerBuilder.safeRunnerForClass(RunnerBuilder.java:57)
at org.junit.internal.builders.AllDefaultPossibilitiesBuilder.runnerForClass(AllDefaultPossibilitiesBuilder.java:29)
at org.junit.runners.model.RunnerBuilder.safeRunnerForClass(RunnerBuilder.java:57)
at org.junit.internal.requests.ClassRequest.getRunner(ClassRequest.java:24)
at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:49)
at com.intellij.rt.execution.junit.IdeaTestRunner$Repeater.startRunnerWithArgs(IdeaTestRunner.java:47)
at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:242)
at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:70)
I was getting above issue. The resolution was to add a javassist dependency (added in test scope)
<dependency>
<groupId>javassist</groupId>
<artifactId>javassist</artifactId>
<version>3.12.1.GA</version>
<scope>test</scope>
</dependency>
Then, I was getting some error like "NoClassDefFound org/mockito/mock/MockNam"
Which was because of the version compatibility issue between Mockito and PoweMock-API. The below mentioned version worked for me
<dependency>
<groupId>org.powermock</groupId>
<artifactId>powermock-module-junit4</artifactId>
<version>1.5.4</version><!--$NO-MVN-MAN-VER$-->
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.powermock</groupId>
<artifactId>powermock-api-mockito</artifactId>
<version>1.4.12</version>
<scope>test</scope>
</dependency>
Thanks everyone for your inputs
@singhdivyas 's comment about upgrading javassist was definitely helpful...fixed a similar issue for me.
Probably fixed by #1043