mockito: Better error message if mock-maker-inline is used on Android
The “mock-maker-inline” is not available on Android, the error message can be optimized so the message “This mock maker is not supported on Android” stands on the first line of the exception.
Currently users must dig in the root cause of the IllegalStateException: Could not initialize plugin: interface org.mockito.plugins.MockMaker.
java.lang.IllegalStateException: Could not initialize plugin: interface org.mockito.plugins.MockMaker
at org.mockito.internal.configuration.plugins.PluginLoader$1.invoke(PluginLoader.java:66)
at com.sun.proxy.$Proxy8.isTypeMockable(Unknown Source)
at org.mockito.internal.util.MockUtil.typeMockabilityOf(MockUtil.java:29)
at org.mockito.internal.util.MockCreationValidator.validateType(MockCreationValidator.java:22)
at org.mockito.internal.creation.MockSettingsImpl.validatedSettings(MockSettingsImpl.java:168)
at org.mockito.internal.creation.MockSettingsImpl.confirm(MockSettingsImpl.java:162)
at org.mockito.internal.MockitoCore.mock(MockitoCore.java:64)
at org.mockito.Mockito.mock(Mockito.java:1693)
at org.mockito.internal.configuration.MockAnnotationProcessor.process(MockAnnotationProcessor.java:33)
at org.mockito.internal.configuration.MockAnnotationProcessor.process(MockAnnotationProcessor.java:16)
at org.mockito.internal.configuration.IndependentAnnotationEngine.createMockFor(IndependentAnnotationEngine.java:38)
at org.mockito.internal.configuration.IndependentAnnotationEngine.process(IndependentAnnotationEngine.java:62)
at org.mockito.internal.configuration.InjectingAnnotationEngine.processIndependentAnnotations(InjectingAnnotationEngine.java:57)
at org.mockito.internal.configuration.InjectingAnnotationEngine.process(InjectingAnnotationEngine.java:41)
at org.mockito.MockitoAnnotations.initMocks(MockitoAnnotations.java:69)
at org.mockito.internal.junit.JUnitRule$1.evaluate(JUnitRule.java:42)
at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:78)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:57)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
at org.junit.runner.JUnitCore.run(JUnitCore.java:137)
at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:119)
at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:42)
at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:234)
at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:74)
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:498)
at com.intellij.rt.execution.application.AppMain.main(AppMain.java:144)
Caused by: java.lang.IllegalStateException: Failed to load interface org.mockito.plugins.MockMaker implementation declared in sun.misc.CompoundEnumeration@73ad2d6
at org.mockito.internal.configuration.plugins.PluginLoader.loadImpl(PluginLoader.java:101)
at org.mockito.internal.configuration.plugins.PluginLoader.loadPlugin(PluginLoader.java:45)
at org.mockito.internal.configuration.plugins.PluginRegistry.<init>(PluginRegistry.java:18)
at org.mockito.internal.configuration.plugins.Plugins.<clinit>(Plugins.java:17)
at org.mockito.internal.configuration.GlobalConfiguration.tryGetPluginAnnotationEngine(GlobalConfiguration.java:55)
at org.mockito.MockitoAnnotations.initMocks(MockitoAnnotations.java:68)
... 20 more
Caused by: org.mockito.exceptions.base.MockitoInitializationException:
Could not initialize inline Byte Buddy mock maker. (This mock maker is not supported on Android.)
Java : 1.8
JVM vendor name : Oracle Corporation
JVM vendor version : 25.76-b03
JVM name : OpenJDK 64-Bit Server VM
JVM version : 1.8.0_76-release-b03
JVM info : mixed mode
OS name : Windows 7
OS version : 6.1
at org.mockito.internal.creation.bytebuddy.InlineByteBuddyMockMaker.<init>(InlineByteBuddyMockMaker.java:172)
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 java.lang.Class.newInstance(Class.java:442)
at org.mockito.internal.configuration.plugins.PluginLoader.loadImpl(PluginLoader.java:96)
... 25 more
Caused by: java.lang.IllegalStateException: Error during attachment using: net.bytebuddy.agent.ByteBuddyAgent$AttachmentProvider$Compound@23d4d935
at net.bytebuddy.agent.ByteBuddyAgent.install(ByteBuddyAgent.java:316)
at net.bytebuddy.agent.ByteBuddyAgent.install(ByteBuddyAgent.java:282)
at net.bytebuddy.agent.ByteBuddyAgent.install(ByteBuddyAgent.java:250)
at net.bytebuddy.agent.ByteBuddyAgent.install(ByteBuddyAgent.java:236)
at org.mockito.internal.creation.bytebuddy.InlineByteBuddyMockMaker.<clinit>(InlineByteBuddyMockMaker.java:102)
... 31 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:498)
at net.bytebuddy.agent.ByteBuddyAgent.install(ByteBuddyAgent.java:303)
... 35 more
Caused by: com.sun.tools.attach.AttachNotSupportedException: no providers installed
at com.sun.tools.attach.VirtualMachine.attach(VirtualMachine.java:208)
... 40 more
About this issue
- Original URL
- State: open
- Created 7 years ago
- Comments: 22 (9 by maintainers)
Commits related to this issue
- Fixes #1855 and #939: improve error message when the inline mock maker cannot be used. — committed to mockito/mockito by raphw 4 years ago
- Fixes #1855 and #939: improve error message when the inline mock maker cannot be used. — committed to mockito/mockito by raphw 4 years ago
- Fixes #1855 and #939: improve error message when the inline mock maker cannot be used. — committed to mockito/mockito by raphw 4 years ago
- [ci maven-central-release] Merge pull request #1974 from mockito/improve-error-message Fixes #1855 and #939: improve error message when the inline mock maker cannot be used. — committed to mockito/mockito by raphw 4 years ago
@raphw I wonder why I see this error at all, since I am running the test locally on a “normal” JVM+JRE not on the device or emulator?!
I ran into this issue after integrating Robolectric into my tests. Is anybody else who sees this error using Robolectric? Could help explain.
any updates for this?
I encountered this too today, when I was trying to add the MockMaker plugin to our project (to mock Kotlin classes, which are final by default). The error said it’s not supported on Android, while I’m testing locally on a normal JVM, similarly to the stack trace above.
It looks like it’s working after upgrading robolectric from 3.1.4 to latest release (3.3.2).
I thought I was running a jdk when this issue happens to me but instead I was using a the jre.
Running the test using the jdk solved the problem for me.
Nevermind - this was caused by using a hack for cleaning up inline mocks to prevent memory leaks. Removing that fixes the issue. Is this memory issue for inline mocking still a problem in newer versions of mockito/byte buddy? (#1614 )
solved by: https://stackoverflow.com/questions/49767683/what-does-no-compatible-attachment-provider-is-not-available-mean