org.mockito.exceptions.base.MockitoException

Mockito cannot mock this class: class java.nio.DirectByteBuffer Mockito can only mock visible & non-final classes. If you're not sure why you're getting this error, please report to the mailing list.

Samebug tips0

We couldn't find tips for this exception.

Don't give up yet. Paste your full stack trace to get a solution.

Solutions on the web113

  • via Unknown by Alexander Pelepeychenko,
  • via Unknown by Unknown author,
  • Stack trace

    • org.mockito.exceptions.base.MockitoException: Mockito cannot mock this class: class java.nio.DirectByteBuffer Mockito can only mock visible & non-final classes. If you're not sure why you're getting this error, please report to the mailing list. at org.powermock.api.mockito.repackaged.ClassImposterizer.createProxyClass(ClassImposterizer.java:131) at org.powermock.api.mockito.repackaged.ClassImposterizer.imposterise(ClassImposterizer.java:57) at org.powermock.api.mockito.internal.mockcreation.MockCreator.createMethodInvocationControl(MockCreator.java:111) at org.powermock.api.mockito.internal.mockcreation.MockCreator.mock(MockCreator.java:59) at org.powermock.api.mockito.PowerMockito.spy(PowerMockito.java:220) at misat.rounddb.EnsurePowerMockTest.addSpyTest(EnsurePowerMockTest.java:34) 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.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:85) at org.testng.internal.Invoker.invokeMethod(Invoker.java:639) at org.testng.internal.Invoker.invokeTestMethod(Invoker.java:816) at org.testng.internal.Invoker.invokeTestMethods(Invoker.java:1124) at org.testng.internal.TestMethodWorker.invokeTestMethods(TestMethodWorker.java:125) at org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:108) at org.testng.TestRunner.privateRun(TestRunner.java:774) at org.testng.TestRunner.run(TestRunner.java:624) at org.testng.SuiteRunner.runTest(SuiteRunner.java:359) at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:354) at org.testng.SuiteRunner.privateRun(SuiteRunner.java:312) at org.testng.SuiteRunner.run(SuiteRunner.java:261) at org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:52) at org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:86) at org.testng.TestNG.runSuitesSequentially(TestNG.java:1191) at org.testng.TestNG.runSuitesLocally(TestNG.java:1116) at org.testng.TestNG.run(TestNG.java:1024) at org.testng.remote.RemoteTestNG.run(RemoteTestNG.java:112) at org.testng.remote.RemoteTestNG.initAndRun(RemoteTestNG.java:205) at org.testng.remote.RemoteTestNG.main(RemoteTestNG.java:176) at org.testng.RemoteTestNGStarter.main(RemoteTestNGStarter.java:125) 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 com.intellij.rt.execution.application.AppMain.main(AppMain.java:140) Caused by: org.mockito.cglib.core.CodeGenerationException: java.lang.reflect .InvocationTargetException-->null at org.mockito.cglib.core.AbstractClassGenerator.create(AbstractClassGenerator.java:238) at org.mockito.cglib.proxy.Enhancer.createHelper(Enhancer.java:378) at org.mockito.cglib.proxy.Enhancer.createClass(Enhancer.java:318) at org.powermock.api.mockito.repackaged.ClassImposterizer.createProxyClass(ClassImposterizer.java:123) ... 35 more Caused by: java.lang.reflect.InvocationTargetException 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.mockito.cglib.core.ReflectUtils.defineClass(ReflectUtils.java:385) at org.mockito.cglib.core.AbstractClassGenerator.create(AbstractClassGenerator.java:220) ... 38 more Caused by: java.lang.IllegalAccessError: class $java.nio. DirectByteBuffer$$EnhancerByMockitoWithCGLIB$$d5fb8f36 cannot access its superclass java.nio.DirectByteBuffer at java.lang.ClassLoader.defineClass1(Native Method) at java.lang.ClassLoader.defineClass(ClassLoader.java:760) ... 44 more

    Write tip

    You have a different solution? A short tip here would help you and many other users who saw this issue last week.

    Users with the same issue

    Unknown visitor
    Unknown visitorOnce,
    Unknown visitor
    Unknown visitorOnce,
    Unknown visitor
    Unknown visitorOnce,
    Unknown visitor
    Unknown visitorOnce,
    Unknown visitor
    Unknown visitorOnce,
    27 more bugmates