Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PowerMockAgent does not support java >=10 #979

carstenartur opened this issue Mar 27, 2019 · 1 comment


None yet
1 participant
Copy link

commented Mar 27, 2019

On java 11 you get an error in your junit test when the code in PowerMockAgent is used because of this:

`public final class PowerMockAgent

static final String javaSpecVersion = System.getProperty("java.specification.version");
static final boolean jdk6OrLater = "1.6".equals(javaSpecVersion) || "1.7".equals(javaSpecVersion) || "1.8".equals(javaSpecVersion)
    || "9".equals(javaSpecVersion);


So computing the information about the version after jdk6 or before it does not take into account that for java 11 the javaSpecVersion variable is "11".
Consequently you get the following error:

java.lang.RuntimeException: java.lang.IllegalStateException: PowerMock requires a Java 5 VM or later.
at org.powermock.modules.agent.PowerMockClassRedefiner.redefine(
at org.powermock.modules.junit4.rule.PowerMockRule.apply(
at org.junit.runners.BlockJUnit4ClassRunner.withMethodRules(
at org.junit.runners.BlockJUnit4ClassRunner.withRules(
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(
at java.base/java.lang.reflect.Method.invoke(
at org.springframework.util.ReflectionUtils.invokeMethod(
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.withRulesReflectively(
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.methodBlock(
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(
at org.junit.runners.ParentRunner$
at org.junit.runners.ParentRunner$1.schedule(
at org.junit.runners.ParentRunner.runChildren(
at org.junit.runners.ParentRunner.access$000(
at org.junit.runners.ParentRunner$2.evaluate(
at org.springframework.test.context.junit4.statements.RunBeforeTestClassCallbacks.evaluate(
at org.springframework.test.context.junit4.statements.RunAfterTestClassCallbacks.evaluate(
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(
Caused by: java.lang.IllegalStateException: PowerMock requires a Java 5 VM or later.
at org.powermock.modules.agent.AgentInitialization.initializeAccordingToJDKVersion(
at org.powermock.modules.agent.PowerMockAgent.verifyInitialization(
at org.powermock.modules.agent.PowerMockAgent.instrumentation(
at org.powermock.modules.agent.PowerMockClassRedefiner.redefine(
... 31 more

carstenartur added a commit to carstenartur/powermock that referenced this issue Mar 29, 2019

see powermock#979
Signed-off-by: Carsten Hammer <>

thekingnothing added a commit that referenced this issue Apr 21, 2019

thekingnothing added a commit that referenced this issue Apr 21, 2019

[ci maven-central-release] Fixes #979 Generalise getting current java…
… version to fix be able to use JavaAgent with latest java (#985)

Fixes #979 Generalise getting current java version to fix be able to use Javaagent with the latest java

This comment has been minimized.

Copy link

commented Apr 23, 2019

Could it be that with Java 11 you need additionally "-Djdk.attach.allowAttachSelf=true" to make it run?
Without that I get

Caused by: Can not attach to current VM
at jdk.attach/
at jdk.attach/
at jdk.attach/
at jdk.attach/
at org.powermock.modules.agent.AgentLoader.attachToThisVM(
... 32 more

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.