PowerMock 1.6.4 and Mockito 2: ClassNotFoundException: org.mockito.cglib.proxy.Enhancer

18,505 views
Skip to first unread message

Boti

unread,
Feb 8, 2016, 4:28:09 AM2/8/16
to PowerMock
Hallo,

i'm having a problem with PowerMock/Mockito. I was switched from Mockito 2.0.32-beta to using PowerMock 1.6.4 and Mockito 2.0.41-beta. The Java Version is 1.8.0_72 and junit 4.12. When using mockito 2.0.41 (and other 2.0.x versions) with PowerMock 1.6.4 I always get the stack trace below when I try to run a test. I understand that mockito-core 2.0.x no longer has cglib onboard. From the comments of the 1.6.2 release I concluded, that the missing cglib shouldn't be a problem and that ByteBuddy should be used instead. Am I missing something? Isn't current PowerMock version working with Mockito 2?

I'm always getting that stacktrace:

java.lang.NoClassDefFoundError: org/mockito/cglib/proxy/Enhancer
    at org.powermock.api.extension.proxyframework.ProxyFrameworkImpl.isProxy(ProxyFrameworkImpl.java:50)
    at org.powermock.reflect.internal.WhiteboxImpl.getUnmockedType(WhiteboxImpl.java:1661)
    at org.powermock.reflect.internal.WhiteboxImpl.getType(WhiteboxImpl.java:2085)
    at org.powermock.reflect.internal.WhiteboxImpl.setInternalState(WhiteboxImpl.java:308)
    at org.powermock.reflect.proxyframework.RegisterProxyFramework.registerProxyFramework(RegisterProxyFramework.java:18)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:497)
    at org.powermock.reflect.internal.WhiteboxImpl.performMethodInvocation(WhiteboxImpl.java:1873)
    at org.powermock.reflect.internal.WhiteboxImpl.doInvokeMethod(WhiteboxImpl.java:773)
    at org.powermock.reflect.internal.WhiteboxImpl.invokeMethod(WhiteboxImpl.java:753)
    at org.powermock.reflect.Whitebox.invokeMethod(Whitebox.java:466)
    at org.powermock.tests.utils.impl.AbstractTestSuiteChunkerImpl.registerProxyframework(AbstractTestSuiteChunkerImpl.java:158)
    at org.powermock.tests.utils.impl.AbstractTestSuiteChunkerImpl.getPowerMockTestListenersLoadedByASpecificClassLoader(AbstractTestSuiteChunkerImpl.java:111)
    at org.powermock.modules.junit4.common.internal.impl.JUnit4TestSuiteChunkerImpl.createDelegatorFromClassloader(JUnit4TestSuiteChunkerImpl.java:158)
    at org.powermock.modules.junit4.common.internal.impl.JUnit4TestSuiteChunkerImpl.createDelegatorFromClassloader(JUnit4TestSuiteChunkerImpl.java:40)
    at org.powermock.tests.utils.impl.AbstractTestSuiteChunkerImpl.createTestDelegators(AbstractTestSuiteChunkerImpl.java:244)
    at org.powermock.modules.junit4.common.internal.impl.JUnit4TestSuiteChunkerImpl.<init>(JUnit4TestSuiteChunkerImpl.java:61)
    at org.powermock.modules.junit4.common.internal.impl.AbstractCommonPowerMockRunner.<init>(AbstractCommonPowerMockRunner.java:32)
    at org.powermock.modules.junit4.PowerMockRunner.<init>(PowerMockRunner.java:34)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
    at java.lang.reflect.Constructor.newInstance(Constructor.java:422)
    at org.junit.internal.builders.AnnotatedBuilder.buildRunner(AnnotatedBuilder.java:104)
    at org.junit.internal.builders.AnnotatedBuilder.runnerForClass(AnnotatedBuilder.java:86)
    at org.junit.runners.model.RunnerBuilder.safeRunnerForClass(RunnerBuilder.java:59)
    at org.junit.internal.builders.AllDefaultPossibilitiesBuilder.runnerForClass(AllDefaultPossibilitiesBuilder.java:26)
    at org.junit.runners.model.RunnerBuilder.safeRunnerForClass(RunnerBuilder.java:59)
    at org.junit.internal.requests.ClassRequest.getRunner(ClassRequest.java:33)
    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:444)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:675)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:382)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:192)
Caused by: java.lang.ClassNotFoundException: org.mockito.cglib.proxy.Enhancer
    at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:331)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
    at org.powermock.core.classloader.MockClassLoader.loadModifiedClass(MockClassLoader.java:178)
    at org.powermock.core.classloader.DeferSupportingClassLoader.loadClass(DeferSupportingClassLoader.java:70)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
    ... 39 more


Thanks,
Boti

Johan Haleby

unread,
Feb 8, 2016, 4:29:58 AM2/8/16
to powe...@googlegroups.com
Try putting CgLib on the classpath

--
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.
Visit this group at https://groups.google.com/group/powermock.
For more options, visit https://groups.google.com/d/optout.

Boti

unread,
Feb 8, 2016, 11:27:16 AM2/8/16
to PowerMock
Hallo Johan,

thank you for you reply. I already had cglib in classpath. So no success. It's still searching for "org.mockito.cglib.proxy.Enhancer".

Regards,
Boti


Артур Загретдинов

unread,
Feb 8, 2016, 1:50:25 PM2/8/16
to PowerMock
Hello,

In the release 2.0.32-beta Mockito team moved cglib classes into separated jar (https://github.com/mockito/mockito/issues/248). But PowerMock still depends on classes which have been moved, so you get java.lang.NoClassDefFoundError. 

In release 1.6.2 Mockito classes was copied into PowerMock, but not all. As workaround I may suggest clone and build the mockito-cglib project (https://github.com/mockito/mockito-cglib). 

For future releases there are two options: either deliver mockito-cglib with PowerMock or remove depends from code.  

Best regrads,
Arthur Zagretdinov

Johan Haleby

unread,
Feb 8, 2016, 1:52:37 PM2/8/16
to powe...@googlegroups.com
Thanks for the input Arthur. Do you have any insight when mocktio-cglib will be available in maven central?

Артур Загретдинов

unread,
Feb 10, 2016, 12:24:24 AM2/10/16
to PowerMock
I asked question about availability mockito-clglib in Maven central in mockito ML, but I haven't received response, so I don't have such information. 

понедельник, 8 февраля 2016 г., 21:52:37 UTC+3 пользователь Johan Haleby написал:

Johan Haleby

unread,
Feb 11, 2016, 2:33:00 AM2/11/16
to powe...@googlegroups.com
Please let us know if you find out

Никита Баришок

unread,
Apr 14, 2016, 6:38:39 AM4/14/16
to PowerMock
This issue will be fixed in powermock 1.6.5 

Arthur Zagretdinov

unread,
Apr 19, 2016, 2:10:10 AM4/19/16
to powe...@googlegroups.com
Hello, 

To be honest, the fix has addressed only the issue that Mockito 2 removed cglib and give a way to support Mockito 2 API, but under the hood it still uses Mockito 1 and cglib, however Mockito 2 already uses Bytebuddy. We're going to migrate to Bytebuddy also, but I think it will be implemented only in release 2.0 which could be released in Autumn. 

Best regrads,
Arthur Zagretdinov
arthur.za...@outlook.com
Mobile Phone/Whatsapp: +48 889 532 320
Mobile phone/Telegram: +7 (963) 120 65 67

On 14 Apr 2016, at 12:18, Никита Баришок <nbar...@gmail.com> wrote:

This issue will be fixed in powermock 1.6.5 


stu2...@gmail.com

unread,
Apr 30, 2016, 1:41:45 AM4/30/16
to PowerMock

I found a workaround for the time being.

( I have to use both mockito 2 beta and powermock, due to needing to workaround a bug in mockito 1, and also needing to mock final clases, and it's due tmr, so can't wait ;) ).

I basically just included the powermock easymock api and that pulled in the dependencies I needed to use mockito 2 with powermock.
Can't pull in the mockito api, because I need it to use the beta one (including the api + 2.0 leads to conflicts).

 <!-- We need this to mock Multi-Fetch responses from Riak, which are final -->
<!-- However, we need the beta version of mockito due to bugs (see below),
so we _cannot_ use the mockito api provided by powermock, do _not_ include _powermock-api-mockito, it'll mess stuff up -->
<dependency>
<groupId>org.powermock</groupId>
<artifactId>powermock-module-junit4</artifactId>
<version>1.6.4</version>
<scope>test</scope>
</dependency>
<!--If we don't include this, we get: -->
<!--java.lang.IllegalStateException:
Extension API internal error: org.powermock.api.extension.proxyframework.ProxyFrameworkImpl could not be located in classpath.-->
<!-- it looks like this is due to some discrepancy in packaging with mockito 2, this may be fixed in Fall 2016:
https://groups.google.com/forum/#!topic/powermock/cE4T40Xa_wc -->
<dependency>
<groupId>org.powermock</groupId>
<artifactId>powermock-api-easymock</artifactId>
<version>1.6.4</version>
</dependency>


<!-- We need this fix: https://github.com/mockito/mockito/pull/171 to use mockito with Riak -->
<!--http://stackoverflow.com/questions/28442495/how-to-mock-riak-java-client#28474106-->
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId>
<version>2.0.52-beta</version>
<scope>test</scope>
</dependency>

Johan Haleby

unread,
Apr 30, 2016, 2:38:00 AM4/30/16
to powe...@googlegroups.com
Experminental support for mockito2 is coming in the next version which will be released very soon!

Igor Ganapolsky

unread,
Oct 20, 2016, 1:12:23 AM10/20/16
to PowerMock
If I do that, then I cannot use PowerMockito.
Reply all
Reply to author
Forward
0 new messages