New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Could not initialize inline Byte Buddy mock maker. Linux JDK + Bazel + InlineMockMaker #1879
Comments
Mockito team - feel free to close. I just wanted to flag this for other Bazel users, just in case they hit it too. |
Interesting, the stacktrace does not include the full details. We probably would need some more information as to why it could not initialize the inline mockmaker. |
I assume that Bazle runs tests with some form of class loader isolation. In Java 8, it is not possible to attach to the same VM multiple times if reloading the tools.jar into the VM. This restriction was lifted in Java 9+ if you can update. Alternatively, add the |
Hmm, also ran into the same error with Bazel 3.3 and JDK11
Marking the tests relying on |
@shikhar I was able to get this going (even on Java 8) with these dependencies: <dependencies>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId>
<version>3.6.28</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-inline</artifactId>
<version>3.6.28</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>net.bytebuddy</groupId>
<artifactId>byte-buddy-agent</artifactId>
<version>1.10.18</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>net.bytebuddy</groupId>
<artifactId>byte-buddy</artifactId>
<version>1.10.18</version>
<scope>test</scope>
</dependency>
</dependencies>
|
I´m suddenly running into the same issue under Windows 10
using the following dependencies
EDIT: The project contained an older version of JMockit 'org.jmockit:jmockit:1.24' which was clashing with mockit-inline. Removing JMockit entirely or upgrading it to 1.49 resolves the problem |
I am facing the same issue with "mvn clean install " @mklueh |
Thanks @plaird for creating this issue! I ran into the same issue while migrating from Gradle to Bazel. Adding the However, I'm still confused why this was not a problem for us in Gradle (and presumably it worked for you in Maven). I've double checked that we are using the same JDK, dependency versions, etc. with both build systems. We're also using the Junit platform to launch tests, which I believe is what Gradle does too. And I don't see Gradle starting tests with Is it possible Gradle has some special handling for this issue? Or maybe Bazel's sandboxing on Linux affects things? |
It might be the version resolution. What version of Byte Buddy is actually applied? |
I've tried:
But none of these configurations worked. The relevant part of the stack trace seems to be:
|
It seems like |
This is likely caused by bazelbuild/bazel#3236, with the preferred workaround being to pass the option
This may increase RAM usage if tests write to |
If you are seeing similar issue in mocking static methods in the Android world, you might need to do the following set of things. This is done only because JDK 8 and below don't allow multiple jars to be loaded as java agent.
|
As a note this message:
Was apparently caused by configuring the jvm with a "bad" tmpdir or something like that... (possibly one that didn't exist or what not). Kind of wish the exception message were better... |
The Bazel flag `--incompatible_sandbox_hermetic_tmp` is added to fix some issues with `mockito-core` and `byte-buddy`, e.g. see https://github.com/EngFlow/bazel_invocation_analyzer/actions/runs/7067252322/job/19240379595?pr=151 See mockito/mockito#1879 for a similar issue reported, and bazelbuild/bazel#3236 for the "fix" by specifying `--incompatible_sandbox_hermetic_tmp`. Note that this flag will be set to true by default with Bazel 7, which is expected to be released next week. --------- Signed-off-by: Sara Adams <sara.e.adams@gmail.com>
I don't have a reproducer to offer, and we could not narrow down the exact issue. But we ported a project from Maven -> Bazel build, and found that on some Linux systems (not all) we had test failures with:
Could not initialize inline Byte Buddy mock maker. (This mock maker is not supported on Android.)
These tests have the experimental Mockito InlineMockMaker enabled.
What we found was we could eliminate the error by marking the tests with the 'exclusive' tag in Bazel, which causes them to run serially not in parallel. The tests run fine in parallel on all Macs.
JDK for running tests:
Other versions:
Given the platform specific nature of this, we think this is a JDK issue not Mockito. But posting an issue just in case others hit the same.
Full stack:
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:74)
at com.sun.proxy.$Proxy100.getHandler(Unknown Source)
at org.mockito.internal.util.MockUtil.isMock(MockUtil.java:81)
at org.mockito.internal.util.DefaultMockingDetails.isMock(DefaultMockingDetails.java:32)
at org.springframework.boot.test.mock.mockito.MockReset.get(MockReset.java:106)
at org.springframework.boot.test.mock.mockito.ResetMocksTestExecutionListener.resetMocks(ResetMocksTestExecutionListener.java:81)
at org.springframework.boot.test.mock.mockito.ResetMocksTestExecutionListener.resetMocks(ResetMocksTestExecutionListener.java:69)
at org.springframework.boot.test.mock.mockito.ResetMocksTestExecutionListener.afterTestMethod(ResetMocksTestExecutionListener.java:63)
at org.springframework.test.context.TestContextManager.afterTestMethod(TestContextManager.java:441)
at org.springframework.test.context.junit4.statements.RunAfterTestMethodCallbacks.evaluate(RunAfterTestMethodCallbacks.java:94)
at org.springframework.test.context.junit4.statements.SpringRepeat.evaluate(SpringRepeat.java:84)
at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:251)
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:97)
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.springframework.test.context.junit4.statements.RunBeforeTestClassCallbacks.evaluate(RunBeforeTestClassCallbacks.java:61)
at org.springframework.test.context.junit4.statements.RunAfterTestClassCallbacks.evaluate(RunAfterTestClassCallbacks.java:70)
at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.run(SpringJUnit4ClassRunner.java:190)
at com.google.testing.junit.runner.internal.junit4.CancellableRequestFactory$CancellableRunner.run(CancellableRequestFactory.java:89)
at org.junit.runner.JUnitCore.run(JUnitCore.java:137)
at org.junit.runner.JUnitCore.run(JUnitCore.java:115)
at com.google.testing.junit.runner.junit4.JUnit4Runner.run(JUnit4Runner.java:112)
at com.google.testing.junit.runner.BazelTestRunner.runTestsInSuite(BazelTestRunner.java:153)
at com.google.testing.junit.runner.BazelTestRunner.main(BazelTestRunner.java:84)
Caused by: java.lang.IllegalStateException: Failed to load interface org.mockito.plugins.MockMaker implementation declared in sun.misc.CompoundEnumeration@2459333a
at org.mockito.internal.configuration.plugins.PluginInitializer.loadImpl(PluginInitializer.java:54)
at org.mockito.internal.configuration.plugins.PluginLoader.loadPlugin(PluginLoader.java:57)
at org.mockito.internal.configuration.plugins.PluginLoader.loadPlugin(PluginLoader.java:44)
at org.mockito.internal.configuration.plugins.PluginRegistry.(PluginRegistry.java:22)
at org.mockito.internal.configuration.plugins.Plugins.(Plugins.java:19)
at org.mockito.internal.util.MockUtil.(MockUtil.java:24)
at org.mockito.internal.util.DefaultMockingDetails.isMock(DefaultMockingDetails.java:32)
at org.springframework.boot.test.mock.mockito.MockReset.get(MockReset.java:106)
at org.springframework.boot.test.mock.mockito.ResetMocksTestExecutionListener.resetMocks(ResetMocksTestExecutionListener.java:81)
at org.springframework.boot.test.mock.mockito.ResetMocksTestExecutionListener.resetMocks(ResetMocksTestExecutionListener.java:69)
at org.springframework.boot.test.mock.mockito.ResetMocksTestExecutionListener.beforeTestMethod(ResetMocksTestExecutionListener.java:56)
at org.springframework.test.context.TestContextManager.beforeTestMethod(TestContextManager.java:289)
at org.springframework.test.context.junit4.statements.RunBeforeTestMethodCallbacks.evaluate(RunBeforeTestMethodCallbacks.java:74)
at org.springframework.test.context.junit4.statements.RunAfterTestMethodCallbacks.evaluate(RunAfterTestMethodCallbacks.java:86)
... 19 more
Caused by: org.mockito.exceptions.base.MockitoInitializationException:
Could not initialize inline Byte Buddy mock maker. (This mock maker is not supported on Android.)
The text was updated successfully, but these errors were encountered: