PowerMock and Java 7 (Java 1.7)

7,835 views
Skip to first unread message

Kevin Wong

unread,
Oct 14, 2011, 1:59:10 PM10/14/11
to powe...@googlegroups.com
Are there any known issues with PowerMock and Java 7?  I'm getting this:

java.lang.VerifyError: Expecting a stackmap frame at branch target 71 in method ca.digitalrapids.mediamanager.server.ServerResourceMgrTest.access$0(Lca/digitalrapids/mediamanager/server/ServerResourceMgrTest;)Lca/digitalrapids/mediamanager/server/ServerMain; at offset 61
at java.lang.Class.getDeclaredMethods0(Native Method)
at java.lang.Class.privateGetDeclaredMethods(Class.java:2442)
at java.lang.Class.privateGetPublicMethods(Class.java:2562)
at java.lang.Class.getMethods(Class.java:1427)
at org.powermock.modules.junit4.internal.impl.PowerMockJUnit44RunnerDelegateImpl.getTestMethods(PowerMockJUnit44RunnerDelegateImpl.java:93)
at org.powermock.modules.junit4.internal.impl.PowerMockJUnit44RunnerDelegateImpl.<init>(PowerMockJUnit44RunnerDelegateImpl.java:69)
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:525)
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:26)
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:525)
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 org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.<init>(JUnit4TestReference.java:33)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestClassReference.<init>(JUnit4TestClassReference.java:25)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestLoader.createTest(JUnit4TestLoader.java:48)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestLoader.loadTests(JUnit4TestLoader.java:38)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:452)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)

Johan Haleby

unread,
Oct 17, 2011, 2:24:54 AM10/17/11
to powe...@googlegroups.com
I haven't tried PowerMock and Java7 so I don't know. Perhaps you can google for "javassist java7" and try to see if you find anything there (it could possibly be the cause if it). Otherwise I don't know yet.

/Johan

--
You received this message because you are subscribed to the Google Groups "PowerMock" group.
To view this discussion on the web visit https://groups.google.com/d/msg/powermock/-/6JfbY9q2tggJ.
To post to this group, send email to powe...@googlegroups.com.
To unsubscribe from this group, send email to powermock+...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/powermock?hl=en.

Graham Polley

unread,
Nov 4, 2011, 4:29:24 PM11/4/11
to PowerMock
I am also getting the same error after switching to Java7. No problems
on anything < 7. Can't find anything meaningful when going for
"javassist java7"

@Kevin: Did you find a solution (apart from switching back to < 7!)?

On Oct 17, 7:24 am, Johan Haleby <johan.hal...@gmail.com> wrote:
> I haven't tried PowerMock and Java7 so I don't know. Perhaps you can google
> for "javassist java7" and try to see if you find anything there (it could
> possibly be the cause if it). Otherwise I don't know yet.
>
> /Johan
>

Dave

unread,
Nov 4, 2011, 4:15:15 PM11/4/11
to PowerMock
We are seeing a similar problem after upgrading our project to Java 7.
We are using powermock and mockito. We upgraded everything (javassist
3.15.0, mockito 1.8.5, junit 4.8.2, powermockito 1.4.10) and the error
persists when we run the unit tests.

I scoured the javassist issue db and didn't find anything related to
Java 7 incompatibilities.

java.lang.VerifyError: Inconsistent stackmap frames at branch target
40 in method com.xxx.orion.core.util.test.OrionTestCase.<init>()V at
offset 26
at java.lang.Class.getDeclaredMethods0(Native Method)
at java.lang.Class.privateGetDeclaredMethods(Class.java:2442)
at java.lang.Class.privateGetPublicMethods(Class.java:2562)
at java.lang.Class.getMethods(Class.java:1427)
at
org.powermock.modules.junit4.internal.impl.PowerMockJUnit44RunnerDelegateImpl.getTestMethods(PowerMockJUnit44RunnerDelegateImpl.java:
108)
at
org.powermock.modules.junit4.internal.impl.PowerMockJUnit44RunnerDelegateImpl.<init>(PowerMockJUnit44RunnerDelegateImpl.java:
84)
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:525)
at
org.powermock.modules.junit4.common.internal.impl.JUnit4TestSuiteChunkerImpl.createDelegatorFromClassloader(JUnit4TestSuiteChunkerImpl.java:
154)
at
org.powermock.modules.junit4.common.internal.impl.JUnit4TestSuiteChunkerImpl.createDelegatorFromClassloader(JUnit4TestSuiteChunkerImpl.java:
49)
at
org.powermock.tests.utils.impl.AbstractTestSuiteChunkerImpl.createTestDelegators(AbstractTestSuiteChunkerImpl.java:
231)
at
org.powermock.modules.junit4.common.internal.impl.JUnit4TestSuiteChunkerImpl.<init>(JUnit4TestSuiteChunkerImpl.java:
69)
at
org.powermock.modules.junit4.common.internal.impl.AbstractCommonPowerMockRunner.<init>(AbstractCommonPowerMockRunner.java:
35)
at
org.powermock.modules.junit4.PowerMockRunner.<init>(PowerMockRunner.java:
27)
com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:
38)
at
com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:
199)
at
com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:
62)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:
57)
at com.intellij.rt.execution.application.AppMain.main(AppMain.java:
120)

On Oct 16, 11:24 pm, Johan Haleby <johan.hal...@gmail.com> wrote:
> I haven't tried PowerMock and Java7 so I don't know. Perhaps you can google
> for "javassist java7" and try to see if you find anything there (it could
> possibly be the cause if it). Otherwise I don't know yet.
>
> /Johan
>

Dave

unread,
Nov 4, 2011, 7:53:21 PM11/4/11
to PowerMock
Also getting the same error (different source, but same exception)
after upgrading to Java 7.

Graham Polley

unread,
Nov 5, 2011, 1:29:07 PM11/5/11
to powe...@googlegroups.com

Dito. We are also using mocktio & powermock and downloaded all latest versions of all jars. Cant find anything related to javaassist on their site.

As soon as we switch to java 7 we get that error and the tests fail.

Would appear to be a clear incompatibility problem with 7.

Any plans to test with Java 7?

Johan Haleby

unread,
Jun 12, 2012, 4:16:02 AM6/12/12
to powe...@googlegroups.com
Thanks for your comments Ed. I'm actually not sure that it's a bug in PowerMock if you read the latest comment on the issue (it might be a Javassist issue). I've investigated it a bit but I'm quite stuck :/

Regards,
/Johan

On Tue, Jun 12, 2012 at 9:45 AM, Ed Gunter <edwin.g...@googlemail.com> wrote:
We are using latest Junit and Powermock together IBM JDK 1.6 , 1.7 ... and we a running in the exact same problem.
Anyway, I found this google group posting ... and luckily I then checked the "issues" for powermock at google, leading to this 
bug ticket: 


Long story short: there is a workaround (JVM command line switch) that prevents the exception:

quoting

"JVM flag -XX:-UseSplitVerifier to turn off the split verifier, which is what javassist is ultimately breaking.
http://stackoverflow.com/questions/7970622/java-7-jvm-verifyerror-in-eclipse"

It seems like there is still a bug in the powermock code itself, but from reading the rest of the ticket I get the impression
that it will not be fixed soon ...

--
You received this message because you are subscribed to the Google Groups "PowerMock" group.
To view this discussion on the web visit https://groups.google.com/d/msg/powermock/-/UluqE0wTO-IJ.

Johan Haleby

unread,
Feb 18, 2013, 9:45:23 AM2/18/13
to powe...@googlegroups.com
Hi, 
  1. What are the "weird messages" you're getting?
  2. I've never experienced this, doesn't sound too good.
  3. How does manifest itself?
  4. Are you using the classloader- or Java agent based PowerMock runner?
Regards,
/Johan

On Mon, Feb 18, 2013 at 3:29 PM, Markus Karg <headcr...@googlemail.com> wrote:
I wanted to warmup this rather old discussion on Java 7. I am experienced major problems as soon as compiling on JDK 7. These are so strong that I cannot use PowerMock on that platform actually.
 
Some examples...
 
* Weird messages when not using -XX:-UseSplitVerifier
* @PrepareForTest -- With some classes hangs up totally (GC timeout after some minutes)
* mockStatic -- Does something "strange" which leads to the fact that JaCoCo denies to touch the class anymore
 
It would be great if one of the authors could give some insight when PowerMock can be used completely with JDK 7... :-)
 

--
You received this message because you are subscribed to the Google Groups "PowerMock" group.
To unsubscribe from this group and stop receiving emails from it, send an email to powermock+...@googlegroups.com.

To post to this group, send email to powe...@googlegroups.com.

Markus Karg

unread,
Feb 19, 2013, 10:53:17 AM2/19/13
to powe...@googlegroups.com
Thank you for helping me. I digged into it a little deeper and discovered that the problem seems actually is not JDK 7 related -- I apparently just though so because when I added "-XX:-UseSplitVerifier" the most problems did not occur anymore. In fact, I actually had some stack traces with "Inconsistent stackmap frames" in the past, but I cannot reproduce those bugs currently, so I want to concentrate on those I can in the following:
 
1. The "weird messages" is a stack trace complaining about "Inconsistent stackmap frames" for some PowerMock use cases, "java.lang.ArrayIndexOutOfBoundsException" at @PrepareForTest (even in an otherwise empty test class) for others, and a GC timeout when using mockStatic.
 
2. I can reproduce even in a minimal Maven setup, and it happens in Eclipse, too. If you want to can send you a minimal Maven project showcasing the problems.
 
3. See above. Just run "mvn test" and you'll get the exceptions and hangs.
 
4. As I have to use @RunWith(Theories.class), I cannot use either, but I have to use the PowerMock @Rule.
 
Today I concentrated on the ArrayIndexOutOfBoundsException showing up at @PrepareForTest. At least that one is not related to Java 7, even when it is gone as soon as using -XX:-UseSplitVerifier: It only occurs when JaCoCo is used together with PowerMock. I don't know why but if JaCoCo is removed, the problems are gone. I think the mockStatic is also not existing then. The problem is that the JaCoCo people say that this is a failure of PowerMock, it would "produce strange frames" whatever that means. So now I am sitting between two chairs: The PowerMock people and the JaCoCo people. :-(
 
Thanks!
-Markus

Johan Haleby

unread,
Feb 20, 2013, 1:37:19 AM2/20/13
to powe...@googlegroups.com
Hi, 

I'll reply inline.

On Tue, Feb 19, 2013 at 4:53 PM, Markus Karg <headcr...@googlemail.com> wrote:
Thank you for helping me. I digged into it a little deeper and discovered that the problem seems actually is not JDK 7 related -- I apparently just though so because when I added "-XX:-UseSplitVerifier" the most problems did not occur anymore. In fact, I actually had some stack traces with "Inconsistent stackmap frames" in the past, but I cannot reproduce those bugs currently, so I want to concentrate on those I can in the following:
 
1. The "weird messages" is a stack trace complaining about "Inconsistent stackmap frames" for some PowerMock use cases, "java.lang.ArrayIndexOutOfBoundsException" at @PrepareForTest (even in an otherwise empty test class) for others, and a GC timeout when using mockStatic.

Ok
 
 
2. I can reproduce even in a minimal Maven setup, and it happens in Eclipse, too. If you want to can send you a minimal Maven project showcasing the problems.

That would probably be helpful. Perhaps you can create an issue at the issue tracker and attach it there and then notify me?
 
 
3. See above. Just run "mvn test" and you'll get the exceptions and hangs.
 
4. As I have to use @RunWith(Theories.class), I cannot use either, but I have to use the PowerMock @Rule.
 
Today I concentrated on the ArrayIndexOutOfBoundsException showing up at @PrepareForTest. At least that one is not related to Java 7, even when it is gone as soon as using -XX:-UseSplitVerifier: It only occurs when JaCoCo is used together with PowerMock. I don't know why but if JaCoCo is removed, the problems are gone. I think the mockStatic is also not existing then. The problem is that the JaCoCo people say that this is a failure of PowerMock, it would "produce strange frames" whatever that means. So now I am sitting between two chairs: The PowerMock people and the JaCoCo people. :-(

Have you tried both Rule implementations of PowerMock? There's one classloader based rule and one Java agent based rule and I think the latter is more stable. Remember that both rules are experimental. 

PowerMock uses a framework called Javassist to do byte-code manipulation there could be a bug in Javassist that makes it "produce strange frames". Let's see if there's something we can change in PowerMock after you've attached the maven project.

Markus Karg

unread,
Feb 20, 2013, 6:10:41 AM2/20/13
to powe...@googlegroups.com
Thanks for this ideas. I'll try to do this within this week and publish my results. :-)

Markus Karg

unread,
Feb 20, 2013, 6:24:31 AM2/20/13
to powe...@googlegroups.com
One question. You said there is an agent-based rule. I cannot find info about that on http://code.google.com/p/powermock/wiki/PowerMockRule. How to enable that rule?
What I just tried is using XStream vs. Objenenis and the result is that with XStream the ArrayOutOfBoundsException is gone.

Johan Haleby

unread,
Feb 20, 2013, 6:48:49 AM2/20/13
to powe...@googlegroups.com
Here can find documentation here: https://code.google.com/p/powermock/wiki/PowerMockAgent

On Wed, Feb 20, 2013 at 12:24 PM, Markus Karg <headcr...@googlemail.com> wrote:
One question. You said there is an agent-based rule. I cannot find info about that on http://code.google.com/p/powermock/wiki/PowerMockRule. How to enable that rule?
What I just tried is using XStream vs. Objenenis and the result is that with XStream the ArrayOutOfBoundsException is gone.

--

Markus Karg

unread,
Feb 21, 2013, 3:27:19 AM2/21/13
to powe...@googlegroups.com
Johan, thank you so much for your kind help. I have tried out what you told me and here is the result. I uploaded the sample project (http://powermock.googlecode.com/issues/attachment?aid=4320000000&name=powermockito-jacoco-failure.zip&token=BS6zncOnC3CvHH9bT1ODIxbVOb4%3A1361435185227) to the issue tracker (issue 432 http://code.google.com/p/powermock/issues/detail?id=432). Hope you know a solution for us, as we are really desparate! :-)
 
Depending on which type of classloading and which type of rule implementation is used, the result is different:
* powermock-module-junit4-rule + powermock-classloading-xstream:
    + tests succeed (hence a.b.c.d1.A.getC() IS covered -- see test code)
    - target/site/jacoco/index.html a.b.c.d1.A.getC() says 0%
* powermock-module-junit4-rule + powermock-classloading-objenesis
    - one test fails
      - java.lang.ArrayIndexOutOfBoundsException: 5 at a.b.c.d1.WhenNewTest.shouldMockConstructor(WhenNewTest.java)
* powermock-module-junit4-rule-agent + powermock-classloading-objenesis
    - both tests fail
      - Cannot subclass final class a.b.c.d1.B
      - Expecting a stackmap frame at branch target 21 in method a.b.c.d2.H.<init>/La/b/c/d2/G;)V at offset 11
* powermock-module-junit4-rule-agent + powermock-classloading-xstream
    - both tests fail
        - Cannot subclass final class a.b.c.d1.B
        - Expecting a stackmap frame at branch target 21 in method a.b.c.d2.H.<init>(La/b/c/d2/G;)V at offset 11
 
Both, powermock and JaCoCo are really great tools and we appreciate the hard work of the authors, but unless both work fine together we really have the problem that we are totally stuck with our QA. Hence we really beg for a working solution! :-)
 
Thanks so much!
-Markus
Reply all
Reply to author
Forward
0 new messages