Skip to content
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

Mockito.mock fails with BlockHound #152

Closed
Mert-Z opened this issue Oct 19, 2020 · 5 comments
Closed

Mockito.mock fails with BlockHound #152

Mert-Z opened this issue Oct 19, 2020 · 5 comments

Comments

@Mert-Z
Copy link

Mert-Z commented Oct 19, 2020

Mockito.mock fails when blockhound-junit-platform is added to project dependencies.

Expected Behavior

Removing blockhound-junit-platform from dependencies makes the tests pass. I'd expect tests to pass with BlockHound.

Actual Behavior

[ERROR] testSomeScenario  Time elapsed: 0.001 s  <<< ERROR!
java.lang.IllegalStateException: Could not initialize plugin: interface org.mockito.plugins.MockMaker (alternate: null)
        at SomeServiceUTest.testSomeScenario(SomeServiceUTest.java:32)
Caused by: java.lang.IllegalStateException: Failed to load interface org.mockito.plugins.MockMaker implementation declared in sun.misc.CompoundEnumeration@b90c5a5
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    : AdoptOpenJDK
JVM vendor version : 25.242-b08
JVM name           : OpenJDK 64-Bit Server VM
JVM version        : 1.8.0_242-b08
JVM info           : mixed mode
OS name            : Mac OS X
OS version         : 10.14.6

Caused by: java.lang.IllegalStateException: Error during attachment using: net.bytebuddy.agent.ByteBuddyAgent$AttachmentProvider$Compound@30c03473
Caused by: java.lang.reflect.InvocationTargetException
Caused by: java.lang.UnsatisfiedLinkError: Native Library /Library/Java/JavaVirtualMachines/adoptopenjdk-8.jdk/Contents/Home/jre/lib/libattach.dylib already loaded in another classloader

Steps to Reproduce

@Test
public void testSomeScenario() {
    mock(Object.class);
}

Possible Solution

Looks like Byte Buddy dependency pulled transitively by mockito-core doesn't play nicely with the shaded copy of Byte Buddy included in BlockHound library.

+- org.mockito:mockito-core:jar:3.3.3:test
|  +- net.bytebuddy:byte-buddy:jar:1.10.14:test
|  +- net.bytebuddy:byte-buddy-agent:jar:1.10.14:test
|  \- org.objenesis:objenesis:jar:2.6:test

Your Environment

  • io.projectreactor.tools:blockhound-junit-platform:jar:1.0.4.RELEASE
  • org.mockito:mockito-core:jar:3.3.3 (via org.springframework.boot:spring-boot-starter-test:jar:2.3.4.RELEASE)
  • org.springframework.boot:spring-boot-starter-reactor-netty:jar:2.3.4.RELEASE (via org.springframework.boot:spring-boot-starter-webflux:jar:2.3.4.RELEASE)
  • io.projectreactor:reactor-test:jar:3.3.10.RELEASE
  • 1.8.0_242-b08 OpenJDK 64-Bit Server VM
  • Mac OS X 10.14.6
@bsideup
Copy link
Contributor

bsideup commented Oct 19, 2020

@Mert-Z please report it to Mockito. As to the shaded copy of BB, see #70.

@bsideup bsideup closed this as completed Oct 19, 2020
@Mert-Z
Copy link
Author

Mert-Z commented Oct 20, 2020

@bsideup any chance releasing a BlockHound version without shaded Byte Buddy included in it?

@Mert-Z
Copy link
Author

Mert-Z commented Oct 20, 2020

@bsideup any chance releasing a BlockHound version without shaded Byte Buddy included in it?

ah sorry ignore me.. just seen this #70 (comment)

@Mert-Z
Copy link
Author

Mert-Z commented Oct 20, 2020

@bsideup any chance releasing a BlockHound version without shaded Byte Buddy included in it?

ah sorry ignore me.. just seen this #70 (comment)

as a side note, adding JNA to classpath made no difference.

@bsideup
Copy link
Contributor

bsideup commented Oct 20, 2020

as a side note, adding JNA to classpath made no difference.

This is weird. Adding JNA makes ByteBuddy prefer the emulated attachment strategy, and it should work fine. Since Mockito is maintained by the same person who created ByteBuddy, I would say reporting the issue to them would be the best play. The reproducer can be simplified to:

  1. BlockHound.install()
  2. Mockito.mock(Object.class)

no need to use the junit jupiter integration actually

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants