reactor / BlockHound

Java agent to detect blocking calls from non-blocking threads.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Mockito.mock fails with BlockHound

Mert-Z opened this issue · comments

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

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

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

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

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

@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.

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