PowerMockRule problem when used with XML parsing code

1,798 views
Skip to first unread message

jay

unread,
Apr 8, 2011, 8:46:04 AM4/8/11
to PowerMock, jayagopi....@tapiola.fi
Hi Johan,

Without the PowerMockRule, the code runs ok.

With the PowerMockRule in place, this piece of test code works fine,
if the newInstance() call specifies the XML impl class and the
classloader, but FAILS if
the same newInstance() call is done WITHOUT any args :

import org.junit.Rule;
import org.junit.Test;
import org.powermock.modules.junit4.rule.PowerMockRule;

public class JayTest {

@Rule
public PowerMockRule rule = new PowerMockRule();

// crappy test
@Test
public void test1() {

javax.xml.parsers.DocumentBuilderFactory.newInstance("org.apache.xerces.jaxp.DocumentBuilderFactoryImpl",
getClass().getClassLoader() );
//
javax.xml.parsers.DocumentBuilderFactory.newInstance();
System.out.println("JayTest.test1(): works
fine");
}

}

I used the -
Djavax.xml.parsers.DocumentBuilderFactory="org.apache.xerces.jaxp.DocumentBuilderFactoryImpl"
-Djaxp.debug=1 property to see what was happening and found that this
code works, because the classloader is specified. In this
case it is org.powermock.core.classloader.MockClassLoader.
But when the newInstance() args are not specified, then the
classloader seems to be the SUN system classloader sun.misc.Launcher
$AppClassLoader and I get the following exception :
java.lang.ClassCastException:
org.apache.xerces.jaxp.DocumentBuilderFactoryImpl incompatible with
javax.xml.parsers.DocumentBuilderFactory
at
javax.xml.parsers.DocumentBuilderFactory.newInstance(Unknown Source)
at
fi.tapiola.tita.jay.powermock.test.JayTest.test1(JayTest.java:16)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native
Method)
at
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:
48)
at
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:
25)
at java.lang.reflect.Method.invoke(Method.java:600)
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.powermock.modules.junit4.rule.PowerMockStatement
$1.run(PowerMockRule.java:52)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native
Method)
at
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:
48)
at
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:
25)
at java.lang.reflect.Method.invoke(Method.java:600)
at
org.powermock.reflect.internal.WhiteboxImpl.performMethodInvocation(WhiteboxImpl.java:
2042)
at
org.powermock.reflect.internal.WhiteboxImpl.doInvokeMethod(WhiteboxImpl.java:
913)
at
org.powermock.reflect.internal.WhiteboxImpl.invokeMethod(WhiteboxImpl.java:
741)
at
org.powermock.reflect.Whitebox.invokeMethod(Whitebox.java:401)
at
org.powermock.classloading.ClassloaderExecutor.execute(ClassloaderExecutor.java:
98)
at
org.powermock.classloading.ClassloaderExecutor.execute(ClassloaderExecutor.java:
78)
at
org.powermock.modules.junit4.rule.PowerMockStatement.evaluate(PowerMockRule.java:
49)
at
org.junit.runners.BlockJUnit4ClassRunner.runNotIgnored(BlockJUnit4ClassRunner.java:
79)
at
org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:
71)
at
org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:
49)
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.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:
49)
at
org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:
38)
at
org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:
467)
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)

Any ideas on how to resolve this one ?
We have found the PowerMockRule to be quite unstable.
We are using powermock for easymock 1.4.8 and the powermock-
classloading-xstream-1.4.8.
Thanking you in advance for any assistance.

cheers
jay

Johan Haleby

unread,
Apr 8, 2011, 9:04:34 AM4/8/11
to powe...@googlegroups.com, jay, jayagopi....@tapiola.fi
Hi, 

I don't think this is a problem with the rule but a general problem with PowerMock that has been discussed in the mailing-list before (i.e. I think you'll get the same problem if you're using the PowerMockRunner). I've thought about adding a FAQ for this for over 2 years and today I finally got around to do it :). So please have a look at FAQ #2 and see if it helps.

/Johan


--
You received this message because you are subscribed to the Google Groups "PowerMock" group.
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.


jay

unread,
Apr 8, 2011, 9:41:55 AM4/8/11
to PowerMock
Hi Johan,

Thanks for the quick reply 
First of all, the FAQ is a bit misleading. Item 2 example should be
@PowerMockIgnore({"org.xml.*", "javax.xml.*"}) and not PrepareForTest,
I feel.
Secondly, yes, it fixes the problem in my test ( JayTest.java ).
However, when we try it in our actual testcase( a little more complex
with other libraries etc ), we land up in all sorts of other problems
from other libs( like guice, for example ).
It is very difficult to fix a an old sinking boat with a battered
bottom, if you know what I mean 
But we will keep trying to find those classes that need to be ignored.
If you come up with other tips, please let me know.
Thanks.
cheers,
jay


On Apr 8, 4:04 pm, Johan Haleby <johan.hal...@gmail.com> wrote:
> Hi,
>
> I don't think this is a problem with the rule but a general problem with
> PowerMock that has been discussed in the mailing-list before (i.e. I think
> you'll get the same problem if you're using the PowerMockRunner). I've
> thought about adding a FAQ for this for over 2 years and today I finally got
> around to do it :). So please have a look at
> FAQ<http://code.google.com/p/powermock/wiki/FAQ> #2
> and see if it helps.
>
> /Johan
>
>
>
> On Fri, Apr 8, 2011 at 2:46 PM, jay <jayagopi.jagadee...@kolumbus.fi> wrote:
> > Hi Johan,
>
> > Without the PowerMockRule, the code runs ok.
>
> > With the PowerMockRule in place,  this piece of test code works fine,
> > if the newInstance() call specifies the XML impl class and the
> > classloader, but FAILS if
> > the same newInstance() call is done WITHOUT any args :
>
> > import org.junit.Rule;
> > import org.junit.Test;
> > import org.powermock.modules.junit4.rule.PowerMockRule;
>
> > public class JayTest {
>
> >           @Rule
> >           public PowerMockRule rule = new PowerMockRule();
>
> >           // crappy test
> >           @Test
> >           public void test1() {
>
> > javax.xml.parsers.DocumentBuilderFactory.newInstance("org.apache.xerces.jax­p.DocumentBuilderFactoryImpl",
> > getClass().getClassLoader() );
> >                      //
> > javax.xml.parsers.DocumentBuilderFactory.newInstance();
> >                      System.out.println("JayTest.test1(): works
> > fine");
> >           }
>
> > }
>
> > I used the -
>
> > Djavax.xml.parsers.DocumentBuilderFactory="org.apache.xerces.jaxp.DocumentB­uilderFactoryImpl"
> > -Djaxp.debug=1 property to see what was happening and found that this
> > code works, because the classloader is specified. In this
> > case it is org.powermock.core.classloader.MockClassLoader.
> > But when the newInstance() args are not specified, then the
> > classloader seems to be the SUN system classloader sun.misc.Launcher
> > $AppClassLoader  and I get the following exception :
> > java.lang.ClassCastException:
> > org.apache.xerces.jaxp.DocumentBuilderFactoryImpl incompatible with
> > javax.xml.parsers.DocumentBuilderFactory
> >           at
> > javax.xml.parsers.DocumentBuilderFactory.newInstance(Unknown Source)
> >           at
> > fi.tapiola.tita.jay.powermock.test.JayTest.test1(JayTest.java:16)
> >           at sun.reflect.NativeMethodAccessorImpl.invoke0(Native
> > Method)
> >           at
> > sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:
> > 48)
> >           at
>
> > sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImp­l.java:
> > 25)
> >           at java.lang.reflect.Method.invoke(Method.java:600)
> >           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.j­ava:
> > 41)
> >           at
>
> > org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.ja­va:
> > 20)
> >           at org.powermock.modules.junit4.rule.PowerMockStatement
> > $1.run(PowerMockRule.java:52)
> >           at sun.reflect.NativeMethodAccessorImpl.invoke0(Native
> > Method)
> >           at
> > sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:
> > 48)
> >           at
>
> > sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImp­l.java:
> > 25)
> >           at java.lang.reflect.Method.invoke(Method.java:600)
> >           at
>
> > org.powermock.reflect.internal.WhiteboxImpl.performMethodInvocation(Whitebo­xImpl.java:
> > 2042)
> >           at
>
> > org.powermock.reflect.internal.WhiteboxImpl.doInvokeMethod(WhiteboxImpl.jav­a:
> > 913)
> >           at
> > org.powermock.reflect.internal.WhiteboxImpl.invokeMethod(WhiteboxImpl.java:
> > 741)
> >           at
> > org.powermock.reflect.Whitebox.invokeMethod(Whitebox.java:401)
> >           at
>
> > org.powermock.classloading.ClassloaderExecutor.execute(ClassloaderExecutor.­java:
> > 98)
> >           at
>
> > org.powermock.classloading.ClassloaderExecutor.execute(ClassloaderExecutor.­java:
> > 78)
> >           at
>
> > org.powermock.modules.junit4.rule.PowerMockStatement.evaluate(PowerMockRule­.java:
> > 49)
> >           at
>
> > org.junit.runners.BlockJUnit4ClassRunner.runNotIgnored(BlockJUnit4ClassRunn­er.java:
> > 79)
> >           at
>
> > org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.ja­va:
> > 71)
> >           at
>
> > org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.ja­va:
> > 49)
> >           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.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestRe­ference.java:
> > 49)
> >           at
> > org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:
> > 38)
> >           at
>
> > org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestR­unner.java:
> > 467)
> >           at
>
> > org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestR­unner.java:
> > 683)
> >           at
>
> > org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner­.java:
> > 390)
> >           at
>
> > org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunne­r.java:

Johan Haleby

unread,
Apr 8, 2011, 10:07:01 AM4/8/11
to Jagadeesan Jayagopi, powe...@googlegroups.com
You're right, it should be PowerMockIgnore and not PrepareForTest, my mistake.

I know exactly what you mean but this is unfortunately the way you have to do it if you use PowerMock in integration tests. PowerMock was not designed to be used in integration testing but I've wanted to use it myself from time to time. For example if you just want to replace or stub a particular method to return something else. And yes, then you need to add stuff to PowerMockIgnore. One thing that might be useful could be to add support for adding packages to ignore when creating a MockPolicy. So once you've found the correct packages to ignore you can at least reuse them in all your tests. Another way that to solve to problem would be to write java agent support for PowerMock. But this will take a lot of time which I don't have atm (and doubt that I will in a foreseeable future).

If your test code gets too complex I would advise against using PowerMock at all! Usually you can solve the problem in another way by (in most cases) improving the design in your production code.

/Johan

On Fri, Apr 8, 2011 at 3:40 PM, Jagadeesan Jayagopi <jayagopi....@tapiola.fi> wrote:

Hi Johan,

 

Thanks for the quick reply J

First of all, the FAQ is a bit misleading. Item 2 example should be @PowerMockIgnore({"org.xml.*", "javax.xml.*"}) and not PrepareForTest, I feel.

Secondly, yes, it fixes the problem in my test ( JayTest.java ).

However, when we try it in our actual testcase( a little more complex with other libraries etc ), we land up in all sorts of other problems from other libs( like guice, for example ).

It is very difficult to fix a an old sinking boat with a battered bottom, if you know what I mean J

But we will keep trying to find those classes that need to be ignored.

If you come up with other tips, please let me know.

Thanks.

cheers,

jay

 

Johan Haleby

unread,
Apr 9, 2011, 11:13:44 AM4/9/11
to powe...@googlegroups.com, Jagadeesan Jayagopi
Actually I did find time to write an agent, and that much sooner than expected :). 

Please help me verify if it helps you or not by checking out and build PowerMock from trunk (mvn clean install -Dmaven.javadoc.skip=true). You'll then need to remove the powermock-module-junit4-rule and powermock-classloading-xstream from your current project and instead add the powermock-module-junit4-rule and powermock-module-javaagent snapshots that you've just built. 

It would be awesome if you could try it out and see if you encounter any problems. And also make sure you use Java 6 to avoid manually having to specify the agent jar as a JVM argument. 

/Johan

Johan Haleby

unread,
Apr 9, 2011, 11:19:40 AM4/9/11
to powe...@googlegroups.com, Jagadeesan Jayagopi
That should be "instead add the powermock-module-junit4-rule-agent and powermock-module-javaagent"

jay

unread,
Apr 11, 2011, 2:18:38 AM4/11/11
to PowerMock
Thanks Johan. That was fast work :) Very much appreciated.

I am not familiar with Maven. We use ant scripts for building.
It would take a while for us to get acquainted with Maven, install it,
check out PowerMock, build etc.
I would really like to test out your agent solution, but don't have
the time now to invest in Maven.
When you get some time, please test it out, create a release and let
me know.
Thanks for all the assistance.
cheers,
jay

On Apr 9, 6:19 pm, Johan Haleby <johan.hal...@gmail.com> wrote:
> That should be "instead add the powermock-module-junit4-rule-*agent* and
> powermock-module-javaagent"
>
>
>
> On Sat, Apr 9, 2011 at 5:13 PM, Johan Haleby <johan.hal...@gmail.com> wrote:
> > Actually I did find time to write an agent, and that much sooner than
> > expected :).
>
> > Please help me verify if it helps you or not by checking out and build
> > PowerMock from trunk (mvn clean install -Dmaven.javadoc.skip=true). You'll
> > then need to remove the powermock-module-junit4-rule and
> > powermock-classloading-xstream from your current project and instead add
> > the powermock-module-junit4-rule and powermock-module-javaagent snapshots
> > that you've just built.
>
> > It would be awesome if you could try it out and see if you encounter any
> > problems. And also make sure you use Java 6 to avoid manually having to
> > specify the agent jar as a JVM argument.
>
> > /Johan
>
> > On Fri, Apr 8, 2011 at 4:07 PM, Johan Haleby <johan.hal...@gmail.com>wrote:
>
> >> You're right, it should be PowerMockIgnore and not PrepareForTest,
> >> my mistake.
>
> >> I know exactly what you mean but this is unfortunately the way you have to
> >> do it if you use PowerMock in integration tests. PowerMock was not designed
> >> to be used in integration testing but I've wanted to use it myself from time
> >> to time. For example if you just want to replace or stub a particular method
> >> to return something else. And yes, then you need to add stuff to
> >> PowerMockIgnore. One thing that might be useful could be to add support for
> >> adding packages to ignore when creating a MockPolicy<http://code.google.com/p/powermock/wiki/MockPolicies>.
> >>> *From:* Johan Haleby [mailto:johan.hal...@gmail.com]
> >>> *Sent:* 8. huhtikuuta 2011 16:05
> >>> *To:* powe...@googlegroups.com
> >>> *Cc:* jay; Jagadeesan Jayagopi
> >>> *Subject:* Re: [powermock] PowerMockRule problem when used with XML
> >>> parsing code
>
> >>> Hi,
>
> >>> I don't think this is a problem with the rule but a general problem with
> >>> PowerMock that has been discussed in the mailing-list before (i.e. I think
> >>> you'll get the same problem if you're using the PowerMockRunner). I've
> >>> thought about adding a FAQ for this for over 2 years and today I finally got
> >>> around to do it :). So please have a look at FAQ<http://code.google.com/p/powermock/wiki/FAQ> #2
> >>> and see if it helps.
>
> >>> /Johan
>
> >>> On Fri, Apr 8, 2011 at 2:46 PM, jay <jayagopi.jagadee...@kolumbus.fi>
> >>> wrote:
>
> >>> Hi Johan,
>
> >>> Without the PowerMockRule, the code runs ok.
>
> >>> With the PowerMockRule in place,  this piece of test code works fine,
> >>> if the newInstance() call specifies the XML impl class and the
> >>> classloader, but FAILS if
> >>> the same newInstance() call is done WITHOUT any args :
>
> >>> import org.junit.Rule;
> >>> import org.junit.Test;
> >>> import org.powermock.modules.junit4.rule.PowerMockRule;
>
> >>> public class JayTest {
>
> >>>           @Rule
> >>>           public PowerMockRule rule = new PowerMockRule();
>
> >>>           // crappy test
> >>>           @Test
> >>>           public void test1() {
>
> >>> javax.xml.parsers.DocumentBuilderFactory.newInstance("org.apache.xerces.jax­p.DocumentBuilderFactoryImpl",
> >>> getClass().getClassLoader() );
> >>>                      //
> >>> javax.xml.parsers.DocumentBuilderFactory.newInstance();
> >>>                      System.out.println("JayTest.test1(): works
> >>> fine");
> >>>           }
>
> >>> }
>
> >>> I used the -
>
> >>> Djavax.xml.parsers.DocumentBuilderFactory="org.apache.xerces.jaxp.DocumentB­uilderFactoryImpl"
> >>> -Djaxp.debug=1 property to see what was happening and found that this
> >>> code works, because the classloader is specified. In this
> >>> case it is org.powermock.core.classloader.MockClassLoader.
> >>> But when the newInstance() args are not specified, then the
> >>> classloader seems to be the SUN system classloader sun.misc.Launcher
> >>> $AppClassLoader  and I get the following exception :
> >>> java.lang.ClassCastException:
> >>> org.apache.xerces.jaxp.DocumentBuilderFactoryImpl incompatible with
> >>> javax.xml.parsers.DocumentBuilderFactory
> >>>           at
> >>> javax.xml.parsers.DocumentBuilderFactory.newInstance(Unknown Source)
> >>>           at
> >>> fi.tapiola.tita.jay.powermock.test.JayTest.test1(JayTest.java:16)
> >>>           at sun.reflect.NativeMethodAccessorImpl.invoke0(Native
> >>> Method)
> >>>           at
>
> >>> sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:
> >>> 48)
> >>>           at
>
> >>> sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImp­l.java:
> >>> 25)
> >>>           at java.lang.reflect.Method.invoke(Method.java:600)
> >>>           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.j­ava:
> >>> 41)
> >>>           at
>
> >>> org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.ja­va:
> >>> 20)
> >>>           at org.powermock.modules.junit4.rule.PowerMockStatement
> >>> $1.run(PowerMockRule.java:52)
> >>>           at sun.reflect.NativeMethodAccessorImpl.invoke0(Native
> >>> Method)
> >>>           at
>
> >>> sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:
> >>> 48)
> >>>           at
>
> >>> sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImp­l.java:
> >>> 25)
> >>>           at java.lang.reflect.Method.invoke(Method.java:600)
> >>>           at
>
> >>> org.powermock.reflect.internal.WhiteboxImpl.performMethodInvocation(Whitebo­xImpl.java:
> >>> 2042)
> >>>           at
>
> >>> org.powermock.reflect.internal.WhiteboxImpl.doInvokeMethod(WhiteboxImpl.jav­a:
> >>> 913)
> >>>           at
>
> >>> org.powermock.reflect.internal.WhiteboxImpl.invokeMethod(WhiteboxImpl.java:
> >>> 741)
> >>>           at
> >>> org.powermock.reflect.Whitebox.invokeMethod(Whitebox.java:401)
> >>>           at
>
> >>> org.powermock.classloading.ClassloaderExecutor.execute(ClassloaderExecutor.­java:
> >>> 98)
> >>>           at
>
> >>> org.powermock.classloading.ClassloaderExecutor.execute(ClassloaderExecutor.­java:
> >>> 78)
> >>>           at
>
> >>> org.powermock.modules.junit4.rule.PowerMockStatement.evaluate(PowerMockRule­.java:
> >>> 49)
> >>>           at
>
> >>> org.junit.runners.BlockJUnit4ClassRunner.runNotIgnored(BlockJUnit4ClassRunn­er.java:
> >>> 79)
> >>>           at
>
> >>> org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.ja­va:
> >>> 71)
> >>>           at
>
> >>> org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.ja­va:
> >>> 49)
> >>>           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.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestRe­ference.java:
> >>> 49)
> >>>           at
>
> >>> org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:
> >>> 38)
> >>>           at
>
> >>> org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestR­unner.java:
> >>> 467)
> >>>           at
>
> >>> org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestR­unner.java:
> >>> 683)
> >>>           at
>
> >>> org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner­.java:
> >>> 390)
> >>>           at
>
> >>> org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunne­r.java:

AlexN

unread,
Apr 11, 2011, 5:05:55 AM4/11/11
to PowerMock
Hi

I'm working with Jay and we tried to get the latest source, run maven
etc but without much luck.
We have a number of obstacles starting with company proxies and
firewalls and ending with ignorance about Maven. After spending the
morning getting the source and what appears to be correct
configururations to allow Maven outside access, we end up with this
error (DOS cmd output):


C:\workspace\PowerMock\PwerMock-Tita>c:\apache-maven-3.0.3\bin\mvn
clean install -Dmaven.javadoc.skip=true

C:\workspace\PowerMock\PwerMock-Tita>set JAVA_HOME="C:\Progra~1\Java
\jdk1.6.0_12"
[INFO] Scanning for projects...
[ERROR] The build could not read 1 project -> [Help 1]
[ERROR]
[ERROR] The project org.powermock:powermock-classloading-base:1.4.9-
SNAPSHOT (C:\workspace\PowerMock\PwerMock-Tita\cla
ssloading\classloading-base\pom.xml) has 1 error
[ERROR] Non-resolvable parent POM: Could not find artifact
org.powermock:powermock:pom:1.4.9-SNAPSHOT and 'parent.re
lativePath' points at wrong local POM @ line 3, column 10 -> [Help 2]
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with
the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR]
[ERROR] For more information about the errors and possible solutions,
please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/ProjectBuildingException
[ERROR] [Help 2] http://cwiki.apache.org/confluence/display/MAVEN/UnresolvableModelException


Is the 1.4.9-SNAPSHOT missing from the repo or should we do something
else?
If at all possible, could you make the required PowerMock JARs
available for us to test this fix, please?

<= Alex =>

Johan Haleby

unread,
Apr 11, 2011, 5:20:00 AM4/11/11
to powe...@googlegroups.com, AlexN
It might be because you're using Maven 3. Would be too much to ask if you try to build it using Maven2? (I'll fix this as soon as Ubuntu starts shipping maven3)

/Johan


--

Johan Haleby

unread,
Apr 11, 2011, 7:15:50 AM4/11/11
to powe...@googlegroups.com, AlexN
It might also be interesting for your to have a look at the two new projects that are added under "examples" in the PowerMock trunk called "spring-mockito-xml" and "spring-mockito-xml-agent". The first one is using the classloader based PowerMockRule when parsing XML which means that you have to make use of the @PowerMockIgnore annotation. The latter is the same code but instead uses the new java agent based PowerMockRule which means that the test runs fine without using the @PowerMockIgnore annotation.

/Johan

AlexN

unread,
Apr 11, 2011, 7:34:32 AM4/11/11
to PowerMock
Ok, used Maven 2.2.1 instead and it built the jars just fine.
When including the correct jars (going from *-full to *-1.4.9-
SNAPSHOT) the tests executed correctly. So now, this actually works:

import org.junit.Test;

public class JayTest {

@Test
public void test1() {
javax.xml.parsers.DocumentBuilderFactory.newInstance();
System.out.println("JayTest.test1(): works fine");
}
}

No runner, no rule, just the agent. As we are (unfortunately) pretty
much with an IBM JRE then we did have to specify the -javaagent
option. We did try with Sun's JRE too and it worked as you described.

We also tried with the previously failing production tests and things
are now working :)

Both Jay and I very much appreciate your rapid response in getting
this problem solved. Thank you!

Johan Haleby

unread,
Apr 11, 2011, 7:53:15 AM4/11/11
to powe...@googlegroups.com, AlexN
The interesting thing would be if "JayTest" works with the new PowerMockRule (bootstrapped by the agent) but since it works in your other test I think it's ok and it makes me really happy :)

Thank you so much for your help. 
/Johan


--

jay

unread,
Apr 11, 2011, 9:14:11 AM4/11/11
to PowerMock
Hi Johan,

Didn't quite get what you meant by

*......if "JayTest" works with the new PowerMockRule
(bootstrapped by the agent)....*

I thought that your instrumentation oriented implementation *replaces*
the need to bootstrap PowerMock using the @Rule PowerMockRule rule =
new PowerMockRule().
So, my understanding is that if i use the javaagent, then I don't need
to use the Rule.
If that is not the case, please explain.

cheers,
jay

Johan Haleby

unread,
Apr 11, 2011, 9:27:34 AM4/11/11
to powe...@googlegroups.com, jay
No it doesn't eliminate the need of using the PowerMockRule, but it eliminates the need to use @PowerMockIgnore. There are now two different PowerMockRule's available. Before you used the PowerMockRule located in the powermock-module-junit4-rule project which uses classloaders to bootstrap PowerMock byte-code manipulation. The new PowerMockRule is located in the powermock-module-junit4-rule-agent project. So you must still use the (new) PowerMockRule in your code for bootstrapping to work (otherwise PowerMock cannot mock static methods etc). The difference is that way they allow for modifying classes at run-time. Thus you should replace powermock-module-junit4-rule with powermock-module-junit4-rule-agent in your maven pom/ant script/classpath (and remove classloading x-stream) and rerun your tests.

Again refer to the spring-mockito-xml and sping-mockito-xml-agent example projects if you want to understand the difference (the only difference is the changes in the pom.xml and the latter doesn't need to use @PowerMockIgnore to avoid ClassCastException's). 

/Johan


--

jay

unread,
Apr 11, 2011, 9:30:55 AM4/11/11
to PowerMock
Ah! ok, i got it.
Thanks man.
cheers,
jay

Johan Haleby

unread,
Apr 11, 2011, 9:39:00 AM4/11/11
to powe...@googlegroups.com, jay
And please tell me if it works for you or not if you try it out.

Regards,
/Johan

cheers,
jay

nick

unread,
May 3, 2011, 3:45:34 AM5/3/11
to PowerMock
We are also trying to run powermock tests with IBM JRE. When I add the
new 1.4.9 release I cannot acces the PowerMockRule anymore.
The class is in the powermock-mockito-1.4.9-full.jar file, but I can
not use it in my test. I added my powermock-module-junit4-rule-
agent-1.4.9-SNAPSHOT.jar and powermock-module-javaagent-1.4.9-
SNAPSHOT.jar. But when I try to run my test I get a stacktrace: Unable
to enqueue operation: the target VM does not support attach mechanism.
I get this error when I use the PowerMockRule. I need this rule
because I want to mock static/final classes.
AlexN said: "we did have to specify the -javaagent option". Where do I
specify this?

Thanks in advance,

Nick


On Apr 11, 3:39 pm, Johan Haleby <johan.hal...@gmail.com> wrote:
> And please tell me if it works for you or not if you try it out.
>
> Regards,
> /Johan
>

Johan Haleby

unread,
May 3, 2011, 3:58:18 AM5/3/11
to powe...@googlegroups.com
I think it's a miss in the release process :( Since there are now two different PowerMockRule implementations no rule should actually be included in the full jar. As a work-around you must place PowerMockRule of the junit4-rule-agent project before the powermock-x-full.jar in classpath. I'll add it as an issue. 

Since you're not using Maven I'm not quite sure how you would like to bootstrap the agent. This is NOT PowerMock specific so I cannot help you with this. It would be the same if you were to start aspectj load-time weaving etc. But you can see how it's done in Maven here and you need to do something similar.

/Johan

nick van roey

unread,
May 3, 2011, 9:08:20 AM5/3/11
to powe...@googlegroups.com
I think my test-setup is now correct. I am now using the
rule-agent/java-agent from my snapshots and everything runs fine with
sun jdk6. But my project needs to run with ibm jdk6. We are developing
in rad. When we run our tests in eclipse, we get the error:

java.lang.ExceptionInInitializerError
at java.lang.J9VMInternals.initialize(J9VMInternals.java:222)
at JosTest.<init>(JosTest.java:15)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:56)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:39)
at java.lang.reflect.Constructor.newInstance(Constructor.java:527)
at org.junit.runners.BlockJUnit4ClassRunner.createTest(BlockJUnit4ClassRunner.java:209)
at org.junit.runners.BlockJUnit4ClassRunner$1.runReflectiveCall(BlockJUnit4ClassRunner.java:258)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)
at org.junit.runners.BlockJUnit4ClassRunner.methodBlock(BlockJUnit4ClassRunner.java:255)


at org.junit.runners.BlockJUnit4ClassRunner.runNotIgnored(BlockJUnit4ClassRunner.java:79)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:71)

at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:49)
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.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:49)
at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)


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)

Caused by: java.lang.RuntimeException: java.io.IOException: Unable to


enqueue operation: the target VM does not support attach mechanism

at org.powermock.modules.agent.JDK6AgentLoader.loadAgentAndDetachFromThisVM(JDK6AgentLoader.java:118)
at org.powermock.modules.agent.JDK6AgentLoader.loadAgent(JDK6AgentLoader.java:68)
at org.powermock.modules.agent.AgentInitialization.initializeAccordingToJDKVersion(AgentInitialization.java:32)
at org.powermock.modules.agent.PowerMockAgent.initializeIfNeeded(PowerMockAgent.java:75)
at org.powermock.modules.agent.PowerMockAgent.initializeIfPossible(PowerMockAgent.java:89)
at org.powermock.modules.junit4.rule.PowerMockRule.<clinit>(PowerMockRule.java:30)
at java.lang.J9VMInternals.initializeImpl(Native Method)
at java.lang.J9VMInternals.initialize(J9VMInternals.java:200)
... 24 more
Caused by: java.io.IOException: Unable to enqueue operation: the


target VM does not support attach mechanism

at sun.tools.attach.WindowsVirtualMachine.enqueue(Native Method)
at sun.tools.attach.WindowsVirtualMachine.execute(WindowsVirtualMachine.java:78)
at sun.tools.attach.HotSpotVirtualMachine.loadAgentLibrary(HotSpotVirtualMachine.java:56)
at sun.tools.attach.HotSpotVirtualMachine.loadAgentLibrary(HotSpotVirtualMachine.java:77)
at sun.tools.attach.HotSpotVirtualMachine.loadAgent(HotSpotVirtualMachine.java:104)
at org.powermock.modules.agent.JDK6AgentLoader.loadAgentAndDetachFromThisVM(JDK6AgentLoader.java:108)
... 31 more

When we run with ant, our jvm crashes with output:
Unhandled exception
Type=Segmentation error vmState=0x00000000
J9Generic_Signal_Number=00000004 Signal_Number=0000000b
Error_Value=00000000 Signal_Code=00000001
Handler1=00002AAAAACE72C0 Handler2=00002AAAAB076160
InaccessibleAddress=0000000000000068
RDI=0000000000000000 RSI=00002AAAD5DB5C4B RAX=0000000000000008
RBX=00002AAAD5E0BFF0
RCX=000000001EFEC5F0 RDX=0000000000000000 R8=0000000000000000
R9=00002AAAD5E0C330
R10=0000000000000000 R11=0000000000001008 R12=000000001EE80990
R13=0000000000000008
R14=00002AAAAAE4B160 R15=00002AAAD1BC4A10
RIP=00002AAAAFE9EABE GS=0000 FS=0000 RSP=000000001EFEC580
EFlags=0000000000210202 CS=0033 RBP=000000001ED5DC00 ERR=0000000000000004
TRAPNO=000000000000000E OLDMASK=0000000000000000 CR2=0000000000000068
xmm0 0000000041040000 (f: 1090781184.000000, d: 5.389175e-315)
xmm1 000000003f400000 (f: 1061158912.000000, d: 5.242822e-315)
xmm2 00002aaad4d41e00 (f: 3570671104.000000, d: 2.317820e-310)
xmm3 000000001ed5dc00 (f: 517331968.000000, d: 2.555960e-315)
xmm4 0000000000000400 (f: 1024.000000, d: 5.059232e-321)
xmm5 00002aaad1bc4a10 (f: 3518777856.000000, d: 2.317818e-310)
xmm6 00002aaaaae4b160 (f: 2867114240.000000, d: 2.317785e-310)
xmm7 0000000000000400 (f: 1024.000000, d: 5.059232e-321)
xmm8 0000000000000000 (f: 0.000000, d: 0.000000e+00)
xmm9 0000000000000000 (f: 0.000000, d: 0.000000e+00)
xmm10 0000000000000000 (f: 0.000000, d: 0.000000e+00)
xmm11 0000000000000000 (f: 0.000000, d: 0.000000e+00)
xmm12 0000000000000000 (f: 0.000000, d: 0.000000e+00)
xmm13 0000000000000000 (f: 0.000000, d: 0.000000e+00)
xmm14 0000000000000000 (f: 0.000000, d: 0.000000e+00)
xmm15 0000000000000000 (f: 0.000000, d: 0.000000e+00)
Module=/opt/IBM/WebSphere_7.0.0.13/AppServer/java/jre/lib/amd64/default/libjclscar_24.so
Module_base_address=00002AAAAFE50000
Symbol=sun_misc_Unsafe_putLong__Ljava_lang_Object_2JJ
Symbol_address=00002AAAAFE9EA7C
Target=2_40_20100923_065174 (Linux 2.6.18-194.el5)
CPU=amd64 (2 logical CPUs) (0xf285a000 RAM)
----------- Stack Backtrace -----------


Could you please have a look at it? Can you run in rad? Your help is
very very much appreciated!

Thanks in advance.

PS: this is my test

import org.junit.Rule;
import org.junit.Test;
import org.powermock.api.mockito.PowerMockito;
import org.powermock.core.classloader.annotations.PrepareForTest;
import org.powermock.modules.junit4.rule.PowerMockRule;


//@PrepareForTest(value = {MyFinalClass.class,MyStaticClass.class})
@PrepareForTest(value = {MyStaticClass.class})
//@RunWith(PowerMockRunner.class)
public class JosTest {


@Rule
public PowerMockRule rule = new PowerMockRule();

@Test
public void testFinal() throws Exception {
MyFinalClass finalClass = PowerMockito.mock(MyFinalClass.class);
PowerMockito.when(finalClass.getResult()).thenReturn("message from
mock final!!");


System.out.println(finalClass.getResult());
}

@Test
public void testStatic() throws Exception {
PowerMockito.mockStatic(MyStaticClass.class);
PowerMockito.when(MyStaticClass.getResult()).thenReturn("message
from mock static!!");


System.out.println(MyStaticClass.getResult());
}
}

Note: Recompile with -Xlint:unchecked for details.
Unhandled exception
Type=Segmentation error vmState=0x00000000
J9Generic_Signal_Number=00000004 Signal_Number=0000000b
Error_Value=00000000 Signal_Code=00000001
Handler1=00002AAAAACE72C0 Handler2=00002AAAAB076160
InaccessibleAddress=0000000000000068
RDI=0000000000000000 RSI=00002AAAD5DB5C4B RAX=0000000000000008
RBX=00002AAAD5E0BFF0
RCX=000000001EFEC5F0 RDX=0000000000000000 R8=0000000000000000
R9=00002AAAD5E0C330
R10=0000000000000000 R11=0000000000001008 R12=000000001EE80990
R13=0000000000000008
R14=00002AAAAAE4B160 R15=00002AAAD1BC4A10
RIP=00002AAAAFE9EABE GS=0000 FS=0000 RSP=000000001EFEC580
EFlags=0000000000210202 CS=0033 RBP=000000001ED5DC00 ERR=0000000000000004
TRAPNO=000000000000000E OLDMASK=0000000000000000 CR2=0000000000000068
xmm0 0000000041040000 (f: 1090781184.000000, d: 5.389175e-315)
xmm1 000000003f400000 (f: 1061158912.000000, d: 5.242822e-315)
xmm2 00002aaad4d41e00 (f: 3570671104.000000, d: 2.317820e-310)
xmm3 000000001ed5dc00 (f: 517331968.000000, d: 2.555960e-315)
xmm4 0000000000000400 (f: 1024.000000, d: 5.059232e-321)
xmm5 00002aaad1bc4a10 (f: 3518777856.000000, d: 2.317818e-310)
xmm6 00002aaaaae4b160 (f: 2867114240.000000, d: 2.317785e-310)
xmm7 0000000000000400 (f: 1024.000000, d: 5.059232e-321)
xmm8 0000000000000000 (f: 0.000000, d: 0.000000e+00)
xmm9 0000000000000000 (f: 0.000000, d: 0.000000e+00)
xmm10 0000000000000000 (f: 0.000000, d: 0.000000e+00)
xmm11 0000000000000000 (f: 0.000000, d: 0.000000e+00)
xmm12 0000000000000000 (f: 0.000000, d: 0.000000e+00)
xmm13 0000000000000000 (f: 0.000000, d: 0.000000e+00)
xmm14 0000000000000000 (f: 0.000000, d: 0.000000e+00)
xmm15 0000000000000000 (f: 0.000000, d: 0.000000e+00)
Module=/opt/IBM/WebSphere_7.0.0.13/AppServer/java/jre/lib/amd64/default/libjclscar_24.so
Module_base_address=00002AAAAFE50000
Symbol=sun_misc_Unsafe_putLong__Ljava_lang_Object_2JJ
Symbol_address=00002AAAAFE9EA7C
Target=2_40_20100923_065174 (Linux 2.6.18-194.el5)
CPU=amd64 (2 logical CPUs) (0xf285a000 RAM)
----------- Stack Backtrace -----------
sun_misc_Unsafe_putLong__Ljava_lang_Object_2JJ+0x42
(0x00002AAAAFE9EABE [libjclscar_24.so+0x4eabe])
---------------------------------------
JVMDUMP006I Processing dump event "gpf", detail "" - please wait.
JVMDUMP032I JVM requested System dump using
'/home/ant/tools/cruisecontrol/build_trunk/core.20110503.124246.27481.0001.dmp'
in response to an event
JVMDUMP010I System dump written to
/home/ant/tools/cruisecontrol/build_trunk/core.20110503.124246.27481.0001.dmp
JVMDUMP032I JVM requested Snap dump using
'/home/ant/tools/cruisecontrol/build_trunk/Snap.20110503.124246.27481.0002.trc'
in response to an event
JVMDUMP010I Snap dump written to
/home/ant/tools/cruisecontrol/build_trunk/Snap.20110503.124246.27481.0002.trc
JVMDUMP032I JVM requested Java dump using
'/home/ant/tools/cruisecontrol/build_trunk/javacore.20110503.124246.27481.0003.txt'
in response to an event
JVMDUMP010I Java dump written to
/home/ant/tools/cruisecontrol/build_trunk/javacore.20110503.124246.27481.0003.txt
JVMDUMP013I Processed dump event "gpf", detail "".

Johan Haleby

unread,
May 3, 2011, 9:17:20 AM5/3/11
to powe...@googlegroups.com
Hi, 

It looks like the agent is not bootstrapped properly since it's trying to load and attach to the agent programmatically. I don't have the IBM JDK nor RAD so I cannot test this.

/Johan

nick van roey

unread,
May 3, 2011, 9:20:59 AM5/3/11
to powe...@googlegroups.com
I'm sorry, but I dont fully understand what you are saying.
I just have the powermock/mockito jars (als the agent jars) on my
classpath in eclipse.
Then I just run my unit test in eclipse. Is this not the correct way to do it?
What do you exactly mean by bootstrapping the agent?

Sorry for the dumb questions, I just would love to see this fixed :)

Thanks in advance,

Nick

Johan Haleby

unread,
May 3, 2011, 9:29:27 AM5/3/11
to powe...@googlegroups.com
I'm thinking that maybe it's because the VM is not started with the correct parameters like "-javaagent:". Not sure if the parameter are to be the same for IBM JDK. BUT it may be so unfortunate that the agent won't work on other VM's than the JDK. For example  maybe the code cannot detect if an agent is already running on the IBM JDK and then tries to start a new one. I think you need to remote debug the code and see if you can find something if you're 100% sure that the javaagent is actually started with the VM :(

/Johan

AlexN

unread,
May 4, 2011, 1:48:52 AM5/4/11
to PowerMock
Nick, here is one way how to configure the javaagent in RAD/
Eclipse ...

Run -> Run Configurations ...
Left side is a JUnit entry, expand that and select your test.
Click on the Arguments tab and then you can enter your -javaagent line
into the VM arguments box. This is what I used:

-javaagent:C:/workspace/MyProject/lib/powermock-module-
javaagent-1.4.9-SNAPSHOT.jar

Note that from the JRE tab in the same dialogue, you can also make
sure that you have selected the right JRE to use to execute these
tests. I can confirm that specifying the javaagent like this does
work with IBMs JRE, but the auto detecting and loading doesn't (as it
does with Suns now). Basically, you must still specify the -javaagent
option even with IBM JRE v6's

As for classpath, we are not using the "full" jar after building it
ourselves with Maven, we have (in this order):
- powermock-api-easymock-1.4.9-SNAPSHOT.jar
- powermock-api-support-1.4.9-SNAPSHOT.jar
- powermock-core-1.4.9-SNAPSHOT.jar
- powermock-module-javaagent-1.4.9-SNAPSHOT.jar
- powermock-module-junit4-1.4.9-SNAPSHOT.jar
- powermock-module-junit4-rule-agent-1.4.9-SNAPSHOT.jar
- powermock-reflect-1.4.9-SNAPSHOT.jar
( plus the external dependencies )


Johan, with regards to the original problem, the changes certainly
helped get further but there was still something wrong after all. We
have been a bit busy lately so have not had the time to get back to
this but Jay has promised that he will do so.

<= Alex =>

On May 3, 4:29 pm, Johan Haleby <johan.hal...@gmail.com> wrote:
> I'm thinking that maybe it's because the VM is not started with the correct
> parameters like "-javaagent:". Not sure if the parameter are to be the same
> for IBM JDK. BUT it may be so unfortunate that the agent won't work on other
> VM's than the JDK. For example  maybe the code cannot detect if an agent is
> already running on the IBM JDK and then tries to start a new one. I think
> you need to remote debug the code and see if you can find something if
> you're 100% sure that the javaagent is actually started with the VM :(
>
> /Johan
>
> On Tue, May 3, 2011 at 3:20 PM, nick van roey <nick.vanr...@gmail.com>wrote:
>
>
>
> > I'm sorry, but I dont fully understand what you are saying.
> > I just have the powermock/mockito jars (als the agent jars) on my
> > classpath in eclipse.
> > Then I just run my unit test in eclipse. Is this not the correct way to do
> > it?
> > What do you exactly mean by bootstrapping the agent?
>
> > Sorry for the dumb questions, I just would love to see this fixed :)
>
> > Thanks in advance,
>
> > Nick
>
> > On Tue, May 3, 2011 at 3:17 PM, Johan Haleby <johan.hal...@gmail.com>
> > wrote:
> > > Hi,
> > > It looks like the agent is not bootstrapped properly since it's trying to
> > > load and attach to the agent programmatically. I don't have the IBM JDK
> > nor
> > > RAD so I cannot test this.
> > > /Johan
> > > On Tue, May 3, 2011 at 3:08 PM, nick van roey <nick.vanr...@gmail.com>
> > > wrote:
>
> > >> I think my test-setup is now correct. I am now using the
> > >> rule-agent/java-agent from my snapshots and everything runs fine with
> > >> sun jdk6. But my project needs to run with ibm jdk6. We are developing
> > >> in rad. When we run our tests in eclipse, we get the error:
>
> > >> java.lang.ExceptionInInitializerError
> > >>        at java.lang.J9VMInternals.initialize(J9VMInternals.java:222)
> > >>        at JosTest.<init>(JosTest.java:15)
> > >>        at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native
> > >> Method)
> > >>        at
>
> > sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAcce­ssorImpl.java:56)
> > >>        at
>
> > sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstru­ctorAccessorImpl.java:39)
> > >>        at
> > java.lang.reflect.Constructor.newInstance(Constructor.java:527)
> > >>        at
>
> > org.junit.runners.BlockJUnit4ClassRunner.createTest(BlockJUnit4ClassRunner.­java:209)
> > >>        at
>
> > org.junit.runners.BlockJUnit4ClassRunner$1.runReflectiveCall(BlockJUnit4Cla­ssRunner.java:258)
> > >>        at
>
> > org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.­java:15)
> > >>        at
>
> > org.junit.runners.BlockJUnit4ClassRunner.methodBlock(BlockJUnit4ClassRunner­.java:255)
> > >>        at
>
> > org.junit.runners.BlockJUnit4ClassRunner.runNotIgnored(BlockJUnit4ClassRunn­er.java:79)
> > >>        at
>
> > org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.ja­va:71)
> > >>        at
>
> > org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.ja­va:49)
> > >>        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.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestRe­ference.java:49)
> > >>        at
>
> > org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:­38)
> > >>        at
>
> > org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestR­unner.java:467)
> > >>        at
>
> > org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestR­unner.java:683)
> > >>        at
>
> > org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner­.java:390)
> > >>        at
>
> > org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunne­r.java:197)
> > >> Caused by: java.lang.RuntimeException: java.io.IOException: Unable to
> > >> enqueue operation: the target VM does not support attach mechanism
> > >>        at
>
> > org.powermock.modules.agent.JDK6AgentLoader.loadAgentAndDetachFromThisVM(JD­K6AgentLoader.java:118)
> > >>        at
>
> > org.powermock.modules.agent.JDK6AgentLoader.loadAgent(JDK6AgentLoader.java:­68)
> > >>        at
>
> > org.powermock.modules.agent.AgentInitialization.initializeAccordingToJDKVer­sion(AgentInitialization.java:32)
> > >>        at
>
> > org.powermock.modules.agent.PowerMockAgent.initializeIfNeeded(PowerMockAgen­t.java:75)
> > >>        at
>
> > org.powermock.modules.agent.PowerMockAgent.initializeIfPossible(PowerMockAg­ent.java:89)
> > >>        at
>
> > org.powermock.modules.junit4.rule.PowerMockRule.<clinit>(PowerMockRule.java­:30)
> > >>        at java.lang.J9VMInternals.initializeImpl(Native Method)
> > >>        at java.lang.J9VMInternals.initialize(J9VMInternals.java:200)
> > >>        ... 24 more
> > >> Caused by: java.io.IOException: Unable to enqueue operation: the
> > >> target VM does not support attach mechanism
> > >>        at sun.tools.attach.WindowsVirtualMachine.enqueue(Native Method)
> > >>        at
>
> > sun.tools.attach.WindowsVirtualMachine.execute(WindowsVirtualMachine.java:7­8)
> > >>        at
>
> > sun.tools.attach.HotSpotVirtualMachine.loadAgentLibrary(HotSpotVirtualMachi­ne.java:56)
> > >>        at
>
> > sun.tools.attach.HotSpotVirtualMachine.loadAgentLibrary(HotSpotVirtualMachi­ne.java:77)
> > >>        at
>
> > sun.tools.attach.HotSpotVirtualMachine.loadAgent(HotSpotVirtualMachine.java­:104)
> > >>        at
>
> > org.powermock.modules.agent.JDK6AgentLoader.loadAgentAndDetachFromThisVM(JD­K6AgentLoader.java:108)
> > Module=/opt/IBM/WebSphere_7.0.0.13/AppServer/java/jre/lib/amd64/default/lib­jclscar_24.so
> ...
>
> read more »- Hide quoted text -
>
> - Show quoted text -

Johan Haleby

unread,
May 4, 2011, 2:11:24 AM5/4/11
to powe...@googlegroups.com
Thanks Alex for helping out and please supply me some info of the problems you have when you find time to do so.

/Johan


--
Reply all
Reply to author
Forward
0 new messages