praveen1503 / powermock

Automatically exported from code.google.com/p/powermock
Apache License 2.0
0 stars 0 forks source link

rule agent not working with java7 #387

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
What steps will reproduce the problem?
1. Run a test using power mock rule agent on jdk7

What is the expected output? What do you see instead?

The execution fails with the following stack trace.

java.lang.IllegalStateException: Unable to load Java agent; please add 
lib/tools.jar from your JDK to the classpath
    at org.powermock.modules.agent.JDK6AgentLoader.getVirtualMachineImplementationFromEmbeddedOnes(JDK6AgentLoader.java:97)
    at org.powermock.modules.agent.JDK6AgentLoader.loadAgent(JDK6AgentLoader.java:70)
    at org.powermock.modules.agent.AgentInitialization.initializeAccordingToJDKVersion(AgentInitialization.java:40)
    at org.powermock.modules.agent.PowerMockAgent.initializeIfNeeded(PowerMockAgent.java:83)
    at org.junit.runner.Runner.<clinit>(Runner.java:40)
    at org.junit.internal.builders.JUnit4Builder.runnerForClass(JUnit4Builder.java:13)
    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.junit.internal.requests.FilterRequest.getRunner(FilterRequest.java:33)
    at org.apache.maven.surefire.junit4.JUnit4Provider.execute(JUnit4Provider.java:227)
    at org.apache.maven.surefire.junit4.JUnit4Provider.executeTestSet(JUnit4Provider.java:134)
    at org.apache.maven.surefire.junit4.JUnit4Provider.invoke(JUnit4Provider.java:113)
    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.util.ReflectionUtils.invokeMethodWithArray(ReflectionUtils.java:189)
    at org.apache.maven.surefire.booter.ProviderFactory$ProviderProxy.invoke(ProviderFactory.java:165)
    at org.apache.maven.surefire.booter.ProviderFactory.invokeProvider(ProviderFactory.java:85)
    at org.apache.maven.surefire.booter.ForkedBooter.runSuitesInProcess(ForkedBooter.java:103)
    at org.apache.maven.surefire.booter.ForkedBooter.main(ForkedBooter.java:74)

What version of the product are you using? On what operating system?

powermock-module-junit4 1.4.12 and powermock-module-junit4-rule-agent 1.4.12 on 
osx 10.7.3 with jdk 1.7.0_04

Please provide any additional information below.

Note that I've faced this issue when running the test using maven's surefire 
plugin. I have not faced this problem when running from within IntelliJ. The 
difference I've noticed is when running from maven, 
JDK6AgentLoader.getVirtualMachineImplementationFromEmbeddedOnes() gets called 
which throws an exception, while running from IntelliJ 
JDK6AgentLoader.attachToThisVM() gets called which works fine.

I've made sure the rule agent jar is defined first in the classpath in both 
cases.

The issue disappears if I simply switch to java6.

Original issue reported on code.google.com by manohar....@gmail.com on 28 May 2012 at 9:29

GoogleCodeExporter commented 8 years ago
Is there a way for you to patch this?

Original comment by johan.ha...@gmail.com on 30 May 2012 at 7:25

GoogleCodeExporter commented 8 years ago
If want to run it at maven build then you could use this workaround

            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-surefire-plugin</artifactId>
                <version>2.14</version>
                <configuration>
                    <argLine>-javaagent:${settings.localRepository}/org/powermock/powermock-module-javaagent/${powermock.version}/powermock-module-javaagent-${powermock.version}.jar -XX:-UseSplitVerifier</argLine>
                </configuration>
            </plugin>

Original comment by ale...@abashev.ru on 25 Oct 2013 at 8:41

GoogleCodeExporter commented 8 years ago
I've added this to the FAQ

Original comment by johan.ha...@gmail.com on 28 May 2014 at 1:12