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

ByteBudy agent required by Mockito fails to install on GraalVM #1603

Open
mizosoft opened this issue Mar 1, 2024 · 1 comment
Open

ByteBudy agent required by Mockito fails to install on GraalVM #1603

mizosoft opened this issue Mar 1, 2024 · 1 comment

Comments

@mizosoft
Copy link

mizosoft commented Mar 1, 2024

Hello there! Coming from mockito/mockito#3282.

I'm finding trouble running tests that use mockito on GraalVM. This is the full stack trace when running ./gradlew nativeTest:

Failures (1):
  JUnit Jupiter:MockitoTest:test()
    MethodSource [className = 'com.github.mizosoft.pg.MockitoTest', methodName = 'test', methodParameterTypes = '']
    => java.lang.IllegalStateException: Could not initialize plugin: interface org.mockito.plugins.MockMaker (alternate: null)
       org.mockito.internal.configuration.plugins.PluginLoader$1.invoke(PluginLoader.java:85)
       jdk.proxy4/jdk.proxy4.$Proxy67.isTypeMockable(Unknown Source)
       org.mockito.internal.util.MockUtil.typeMockabilityOf(MockUtil.java:78)
       org.mockito.internal.util.MockCreationValidator.validateType(MockCreationValidator.java:22)
       org.mockito.internal.creation.MockSettingsImpl.validatedSettings(MockSettingsImpl.java:275)
       [...]
     Caused by: java.lang.IllegalStateException: Internal problem occurred, please report it. Mockito is unable to load the default implementation of class that is a part of Mockito distribution. Failed to load interface org.mockito.plugins.MockMaker
       org.mockito.internal.configuration.plugins.DefaultMockitoPlugins.create(DefaultMockitoPlugins.java:105)
       org.mockito.internal.configuration.plugins.DefaultMockitoPlugins.getDefaultPlugin(DefaultMockitoPlugins.java:79)
       org.mockito.internal.configuration.plugins.PluginLoader.loadPlugin(PluginLoader.java:75)
       org.mockito.internal.configuration.plugins.PluginLoader.loadPlugin(PluginLoader.java:49)
       org.mockito.internal.configuration.plugins.PluginRegistry.<init>(PluginRegistry.java:29)
       [...]
     Caused by: java.lang.reflect.InvocationTargetException
       java.base@21.0.2/java.lang.reflect.Constructor.newInstanceWithCaller(Constructor.java:502)
       java.base@21.0.2/java.lang.reflect.Constructor.newInstance(Constructor.java:486)
       org.mockito.internal.configuration.plugins.DefaultMockitoPlugins.create(DefaultMockitoPlugins.java:103)
       [...]
     Caused by: org.mockito.exceptions.base.MockitoInitializationException: 
Could not initialize inline Byte Buddy mock maker.

It appears as if your JDK does not supply a working agent attachment mechanism.
Java               : 21
JVM vendor name    : GraalVM Community
JVM vendor version : 21.0.2+13
JVM name           : Substrate VM
JVM version        : 21.0.2+13-jvmci-23.1-b30
JVM info           : serial gc
OS name            : Linux
OS version         : 6.5.0-21-generic

       org.mockito.internal.creation.bytebuddy.InlineDelegateByteBuddyMockMaker.<init>(InlineDelegateByteBuddyMockMaker.java:260)
       org.mockito.internal.creation.bytebuddy.InlineByteBuddyMockMaker.<init>(InlineByteBuddyMockMaker.java:23)
       [...]
     Caused by: java.lang.IllegalStateException: Cannot locate class file for Byte Buddy installer
       net.bytebuddy.agent.ByteBuddyAgent$AgentProvider$ForByteBuddyAgent.createJarFile(ByteBuddyAgent.java:1510)
       net.bytebuddy.agent.ByteBuddyAgent$AgentProvider$ForByteBuddyAgent.resolve(ByteBuddyAgent.java:1550)
       net.bytebuddy.agent.ByteBuddyAgent.install(ByteBuddyAgent.java:636)
       net.bytebuddy.agent.ByteBuddyAgent.install(ByteBuddyAgent.java:616)
       net.bytebuddy.agent.ByteBuddyAgent.install(ByteBuddyAgent.java:568)
       [...]

Check out this repo for reproducibility.

Stack trace indicates that ByteBuddy can't install its agent. Part of installing the agent is knowing where the JAR file is located through Installer.class file location. This of course won't work on GraalVM as no such Jars/files are retained.

@raphw
Copy link
Owner

raphw commented Mar 2, 2024

I think you would need to use the subclass mock maker on Graal. The entire agent mechanism is not supported by Graal.

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