3.7.7 inline can not find MockMethodDispatcher - has worked in 3.2.4
See original GitHub issueHi @raphw ,
I am from Apache Cassandra project where we want to use Mockito to mock static methods, I know this feature was introduced in Mockito 3.4.0, we had version 3.2.4 so I had to update it.
My test where I was mocking statics works fine but update to that version broke other tests and I am not sure why. The exception I am getting all over again is this:
Dependency versions are:
mockito-inline:3.7.7 bytebuddy and bytebuddy-agent: 1.10.20 junit 4.12
I do not have any extension files etc, I just merely bumped versions, we had mockito-core
but as I understand it mockito-inline already includes it so we do not depend on it explicitly.
Any suggestions how to resolve this would be appreciated.
java.lang.IllegalStateException: Could not initialize plugin: interface org.mockito.plugins.MockMaker (alternate: null)
at org.mockito.internal.configuration.plugins.PluginLoader$1.invoke(PluginLoader.java:84)
at com.sun.proxy.$Proxy26.isTypeMockable(Unknown Source)
at org.mockito.internal.util.MockUtil.typeMockabilityOf(MockUtil.java:33)
at org.mockito.internal.util.MockCreationValidator.validateType(MockCreationValidator.java:22)
at org.mockito.internal.creation.MockSettingsImpl.validatedSettings(MockSettingsImpl.java:250)
at org.mockito.internal.creation.MockSettingsImpl.build(MockSettingsImpl.java:232)
at org.mockito.internal.MockitoCore.mock(MockitoCore.java:60)
at org.mockito.Mockito.spy(Mockito.java:2035)
at org.apache.cassandra.distributed.mock.nodetool.InternalNodeProbe.connect(InternalNodeProbe.java:76)
at org.apache.cassandra.distributed.mock.nodetool.InternalNodeProbe.<init>(InternalNodeProbe.java:60)
at org.apache.cassandra.distributed.impl.Instance$DTestNodeTool.<init>(Instance.java:818)
at org.apache.cassandra.distributed.impl.Instance.lambda$nodetoolResult$39(Instance.java:726)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
at io.netty.util.concurrent.FastThreadLocalRunnable.run(FastThreadLocalRunnable.java:30)
at java.lang.Thread.run(Thread.java:748)
Caused by: java.lang.IllegalStateException: Failed to load interface org.mockito.plugins.MockMaker implementation declared in sun.misc.CompoundEnumeration@1a352001
at org.mockito.internal.configuration.plugins.PluginInitializer.loadImpl(PluginInitializer.java:57)
at org.mockito.internal.configuration.plugins.PluginLoader.loadPlugin(PluginLoader.java:65)
at org.mockito.internal.configuration.plugins.PluginLoader.loadPlugin(PluginLoader.java:50)
at org.mockito.internal.configuration.plugins.PluginRegistry.<init>(PluginRegistry.java:19)
at org.mockito.internal.configuration.plugins.Plugins.<clinit>(Plugins.java:16)
at org.mockito.internal.util.MockUtil.<clinit>(MockUtil.java:28)
... 14 more
Caused by: java.lang.reflect.InvocationTargetException
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:423)
at org.mockito.internal.configuration.plugins.PluginInitializer.loadImpl(PluginInitializer.java:52)
... 19 more
Caused by: java.lang.NoClassDefFoundError: org/mockito/internal/creation/bytebuddy/inject/MockMethodDispatcher
at org.mockito.internal.creation.bytebuddy.InlineByteBuddyMockMaker.<init>(InlineByteBuddyMockMaker.java:305)
... 24 more
Caused by: java.lang.ClassNotFoundException: org.mockito.internal.creation.bytebuddy.inject.MockMethodDispatcher
at java.net.URLClassLoader.findClass(URLClassLoader.java:382)
at org.apache.cassandra.distributed.shared.InstanceClassLoader.loadClassInternal(InstanceClassLoader.java:101)
at org.apache.cassandra.distributed.shared.InstanceClassLoader.loadClass(InstanceClassLoader.java:87)
... 25 more
It particularly fails on doing this spy
StorageServiceMBean mock = Mockito.spy(StorageService.instance);
What is interesting is that some code in MockMethodDispatcher is red like this, invalidating caches and restart of IDEA does not seem to help either.
What has happened between Mockito core 3.2.4 and inline 3.7.7 that it stopped to work? 3.4.0 does not work either …
Issue Analytics
- State:
- Created 3 years ago
- Comments:5 (2 by maintainers)
Top GitHub Comments
This has to do with
MockMethodDispatcher.raw
work-a-round (#845) albeit it indeed feels like the class file would be actually be missing from jar itself. The dynamically craftedmockitoboot.jar
containing the actual class derived from the raw is indeed installed successfully to bootstrap classloader but in environments with sophisticated classloading mechanism like OSGi it may not be reachable by theInlineByteBuddyMockMaker
or more specific theInlineBytecodeGenerator
since the classloading test is not done with the classloader that is being actually used for loadingInlineBytecodeGenerator
.https://github.com/robolectric/robolectric/issues/2677#issuecomment-266010717 explains the rationale behind the approach.
I think that it does not correctly resolve the resource. The class loader is queried for getResourceAsStream(name). If this call returns null, the error in question is raised.