java.lang.IncompatibleClassChangeError: Implementing class

3,201 views
Skip to first unread message

Gus

unread,
Jan 25, 2010, 11:18:43 AM1/25/10
to PowerMock
I'm a bit stuck here...

I seem to get this anytime I use PowerMock.create(Class)... I searched
the issues and this forum and didn't find anything about it. I
verified that @PrepareForTest was being picked up, because when I
tried to use EasyMock.create(Class) I got the Logging problem... If I
got rid of @PrepareForTest, the log4j problem went away, and then I
solved it with @PowerMockIgnore({"org.apache.log4j",
"org.apache.commons.logging"}), and put PowerMock.create() back in...

But I still get:

java.lang.IncompatibleClassChangeError: Implementing class
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(ClassLoader.java:620)
at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:
124)
at java.net.URLClassLoader.defineClass(URLClassLoader.java:260)
at java.net.URLClassLoader.access$100(URLClassLoader.java:56)
at java.net.URLClassLoader$1.run(URLClassLoader.java:195)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:188)
at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:268)
at java.lang.ClassLoader.loadClass(ClassLoader.java:251)
at org.powermock.core.classloader.MockClassLoader.loadModifiedClass
(MockClassLoader.java:144)
at org.powermock.core.classloader.DeferSupportingClassLoader.loadClass
(DeferSupportingClassLoader.java:63)
at java.lang.ClassLoader.loadClass(ClassLoader.java:251)
at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:319)
at
org.powermock.api.easymock.internal.signedsupport.SignedSupportingClassProxyFactory.createProxy
(SignedSupportingClassProxyFactory.java:78)
at org.easymock.internal.MocksControl.createMock(MocksControl.java:
51)
at org.powermock.api.easymock.PowerMock.doCreateMock(PowerMock.java:
2155)
at org.powermock.api.easymock.PowerMock.doMock(PowerMock.java:2110)
at org.powermock.api.easymock.PowerMock.createMock(PowerMock.java:92)
at com.aspentech.imos.test.AutoMock.createMock(AutoMock.java:276)
at com.aspentech.imos.test.AutoMock.initMocks(AutoMock.java:262)
at com.aspentech.imos.model.PipelineCycleTest.<init>
(PipelineCycleTest.java:43)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native
Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance
(NativeConstructorAccessorImpl.java:39)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance
(DelegatingConstructorAccessorImpl.java:27)
at java.lang.reflect.Constructor.newInstance(Constructor.java:494)
at
org.powermock.modules.junit4.internal.impl.PowerMockJUnit44RunnerDelegateImpl.createTestInstance
(PowerMockJUnit44RunnerDelegateImpl.java:201)
at
org.powermock.modules.junit4.internal.impl.PowerMockJUnit44RunnerDelegateImpl.createTest
(PowerMockJUnit44RunnerDelegateImpl.java:186)
at
org.powermock.modules.junit4.internal.impl.PowerMockJUnit44RunnerDelegateImpl.invokeTestMethod
(PowerMockJUnit44RunnerDelegateImpl.java:208)
at
org.powermock.modules.junit4.internal.impl.PowerMockJUnit44RunnerDelegateImpl.runMethods
(PowerMockJUnit44RunnerDelegateImpl.java:161)
at
org.powermock.modules.junit4.internal.impl.PowerMockJUnit44RunnerDelegateImpl
$1.run(PowerMockJUnit44RunnerDelegateImpl.java:135)
at org.junit.internal.runners.ClassRoadie.runUnprotected
(ClassRoadie.java:27)
at org.junit.internal.runners.ClassRoadie.runProtected
(ClassRoadie.java:37)
at
org.powermock.modules.junit4.internal.impl.PowerMockJUnit44RunnerDelegateImpl.run
(PowerMockJUnit44RunnerDelegateImpl.java:133)
at
org.powermock.modules.junit4.common.internal.impl.JUnit4TestSuiteChunkerImpl.run
(JUnit4TestSuiteChunkerImpl.java:112)
at
org.powermock.modules.junit4.common.internal.impl.AbstractCommonPowerMockRunner.run
(AbstractCommonPowerMockRunner.java:55)
at com.intellij.rt.junit4.Junit4ClassSuite.run(Junit4ClassSuite.java:
85)
at com.intellij.rt.execution.junit.JUnitStarter.main
(JUnitStarter.java:40)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke
(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke
(DelegatingMethodAccessorImpl.java:25)
at com.intellij.rt.execution.application.AppMain.main(AppMain.java:
90)

Johan Haleby

unread,
Jan 25, 2010, 3:46:52 PM1/25/10
to PowerMock
Hi,

Never seen this before. If you upgrade to Javassist 3.11 do you still
get the same problem? If you do could you please attach an example
demonstrating the issue to our google group?

/Johan

Gus

unread,
Jan 25, 2010, 6:20:47 PM1/25/10
to PowerMock
Still get it with javassist 3.11.0.GA.. (am using powermock-
easymock-1.3.5-full.jar, easymock 2.5.2, and easymock class extension
2.5 )

Test is run both via ant and via intellij with the same results....


import org.junit.Test;
import org.junit.runner.RunWith;
import org.powermock.api.easymock.PowerMock;
import org.powermock.modules.junit4.PowerMockRunner;
import org.powermock.core.classloader.annotations.PowerMockIgnore;
import org.powermock.core.classloader.annotations.PrepareForTest;

@RunWith( value = PowerMockRunner.class )
@PrepareForTest(value = {SomeObject.class})
public class PowerMockBugTest
{
@Test
public void testRecalc() {
PowerMock.createMock( SomeObject.class );
}
}

public class SomeObject
{
private int foo;
private SomeOtherObject bar = new SomeOtherObject();

public int getFoo()
{
return foo;
}

private void setFoo( int foo )
{
bar.notifyMe();
this.foo = foo;
}

public void recalc(int baz) {
setFoo(baz/2);
}
}


public class SomeOtherObject
{
public void notifyMe() {
// consider your self warned :)

Gus

unread,
Jan 25, 2010, 6:23:49 PM1/25/10
to PowerMock
Actually, I simplified it further... you can ignore SomeOtherObject,
and just use this SomeObject...

public class SomeObject
{
private int foo;

public int getFoo()
{
return foo;
}

private void setFoo( int foo )
{

this.foo = foo;
}

public void recalc(int baz) {
setFoo(baz/2);
}
}

On Jan 25, 3:46 pm, Johan Haleby <johan.hal...@gmail.com> wrote:

Johan Haleby

unread,
Feb 2, 2010, 2:24:55 PM2/2/10
to powe...@googlegroups.com
Hi,

I cannot duplicate this. It works perfectly well at my place.

/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.


Ben

unread,
Feb 8, 2010, 11:34:26 AM2/8/10
to PowerMock
Hi Gus,

Which version of JUnit are you using? I am experiencing a similar
problem on our build server, but my tests run OK in Eclipse.
Currently, I am trying to figure out whether it was caused by the
older version of JUnit (version 4.4).

Thanks,

Ben

Aneesh PU

unread,
Mar 3, 2010, 1:07:30 PM3/3/10
to PowerMock
I have the exact same exception happening from within eclipse. I am
using powermock-easymock-1.3.5, Junit 4.4, easymock-2.5.2 and
easymockclassextension-2.5.2. The exception seems to be getting thrown
when I mock the parse method of android.net.Uri

Michael

unread,
Mar 5, 2010, 12:13:03 PM3/5/10
to PowerMock
I wanted to find out if you made any headway on this. I'm running
into the same issue. I was running EasyMock 2.4 with PowerMock 1.2.5
and everything was working fine. However, to get the ability to use
EasyMock's new capture multiple values feature in 2.5.2, I upgraded
both EasyMock and Powermock (2.5.2 and 1.3.5 respectively). Since
then, all hell has broken loose. This is the main issue I'm running
into though so if you have any feedback, it's appreciated. Thanks in
advance!

Michael

On Mar 3, 12:07 pm, Aneesh PU <anees...@gmail.com> wrote:
> I have the exact same exception happening from within eclipse. I am

> usingpowermock-easymock-1.3.5, Junit 4.4,easymock-2.5.2 and


> easymockclassextension-2.5.2. The exception seems to be getting thrown
> when I mock the parse method of android.net.Uri
>
> On Feb 8, 9:34 pm, Ben <wuhanch...@gmail.com> wrote:
>
>
>
> > Hi Gus,
>

> > Whichversionof JUnit are you using? I am experiencing a similar


> > problem on our build server, but my tests run OK in Eclipse.
> > Currently, I am trying to figure out whether it was caused by the
> > olderversionof JUnit (version4.4).
>
> > Thanks,
>
> > Ben
>
> > On Jan 25, 6:23 pm, Gus <gus.h...@gmail.com> wrote:
>
> > > Actually, I simplified it further... you can ignore SomeOtherObject,
> > > and just use this SomeObject...
>
> > > public class SomeObject
> > > {
> > >   private int foo;
>
> > >   public int getFoo()
> > >   {
> > >     return foo;
> > >   }
>
> > >   private void setFoo( int foo )
> > >   {
> > >     this.foo = foo;
> > >   }
>
> > >   public void recalc(int baz) {
> > >     setFoo(baz/2);
> > >   }
>
> > > }
>
> > > On Jan 25, 3:46 pm, Johan Haleby <johan.hal...@gmail.com> wrote:
>
> > > > Hi,
>
> > > > Never seen this before. If you upgrade to Javassist 3.11 do you  still
> > > > get the same problem? If you do could you please attach an example
> > > > demonstrating the issue to our google group?
>
> > > > /Johan
>
> > > > On Jan 25, 5:18 pm, Gus <gus.h...@gmail.com> wrote:
>
> > > > > I'm a bit stuck here...
>

> > > > > I seem to get this anytime I usePowerMock.create(Class)... I searched


> > > > > the issues and this forum and didn't find anything about it. I
> > > > > verified that @PrepareForTest was being picked up, because when I

> > > > > tried to useEasyMock.create(Class) I got the Logging problem... If I


> > > > > got rid of @PrepareForTest, the log4j problem went away, and then I
> > > > > solved it with @PowerMockIgnore({"org.apache.log4j",

> > > > > "org.apache.commons.logging"}), and putPowerMock.create() back in...

Johan Haleby

unread,
Mar 5, 2010, 12:54:30 PM3/5/10
to powe...@googlegroups.com
Hmm could it be the EasyMock version? I've upgraded PowerMock trunk to depend on version 2.5.2 of EasyMock class extensions now. They've changed some stuff internally which could explain why you run into trouble. You could try the trunk version of PowerMock and see if you run into the same issues.

/Johan

Pejvan

unread,
Apr 15, 2010, 11:36:30 AM4/15/10
to PowerMock
I get the same error in my tests. It's very odd.
Has there been any progress on this front since it was reported a few
weeks ago?

On Mar 5, 6:54 pm, Johan Haleby <johan.hal...@gmail.com> wrote:
> Hmm could it be the EasyMock version? I've upgraded PowerMock trunk to
> depend on version 2.5.2 of EasyMock class extensions now. They've changed
> some stuff internally which could explain why you run into trouble. You
> could try the trunk version of PowerMock and see if you run into the same
> issues.
>
> /Johan
>
> > powermock+...@googlegroups.com<powermock%2Bunsu...@googlegroups.com>
> > .

Johan Haleby

unread,
Apr 16, 2010, 2:17:33 AM4/16/10
to powe...@googlegroups.com
Have you tried upgrading EasyMock+EasyMock classextensions to version 2.5.2?

/Johan

Pejvan

unread,
Apr 19, 2010, 10:09:44 AM4/19/10
to PowerMock
Hi Johan,
Thanks a lot for taking the time to reply.
Yes, the issue is now fixed — using the powermock + eazymock full
package (all dependencies included) solved the problem :-)
Cheers,
Pejvan
> > <powermock%2Bunsu...@googlegroups.com<powermock%252Buns...@googlegroups.com>
>
> > > > .
> > > > For more options, visit this group at
> > > >http://groups.google.com/group/powermock?hl=en.
>
> > --
> > 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<powermock%2Bunsu...@googlegroups.com>
> > .
> > For more options, visit this group at
> >http://groups.google.com/group/powermock?hl=en.
>
> --
> 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 athttp://groups.google.com/group/powermock?hl=en.

Johan Haleby

unread,
Apr 19, 2010, 10:13:07 AM4/19/10
to powe...@googlegroups.com
Glad you got it working!

Johan Haleby

unread,
Mar 1, 2013, 1:28:09 AM3/1/13
to powe...@googlegroups.com
It looks to me that there's something more going on. Perhaps you could try to ignore "com.sun.jmx.*" and/or "javax.management.*" using the @PowerMockIgnore annotation.

Regards,
/Johan

On Fri, Mar 1, 2013 at 2:52 AM, Pranay Dalmia <pranay...@gmail.com> wrote:
Hey Johan,

I am using PowerMockito.
Here is what I am doing:

@RunWith(PowerMockRunner.class)
@PrepareForTest(Foo.class)
public class PowerMockTest {

    @Test
    public void testSomething() throws Exception {

        Bar bar = new Bar(null, null, null);
       
        PowerMockito.mockStatic(Foo.class);
        Mockito.when(Foo.someMethod(Mockito.anyString())).thenReturn("success");

    String str = bar.someOtherMethod();
       
    }
}

//Foo is my class which has a static method someMethod()
//Bar calls this static method from someOtherMethod()


I am getting the following error:
java.lang.IncompatibleClassChangeError: Class com.sun.jmx.mbeanserver.JmxMBeanServer does not implement the requested interface javax.management.MBeanServerConnection
...
...
...



I am using the following versions:
powermock-mockito-1.5
mockito-core-1.9.5
junit-4.7
objenesis-1.2
javassist-3.17.1


Help much appreciated!

Thanks
Pranay

--
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.
Reply all
Reply to author
Forward
0 new messages