mockito/mockito · error · MockitoInitializationException

Could not initialize inline Byte Buddy mock maker. <detail>

Error message

Could not initialize inline Byte Buddy mock maker.

<detail>
<platformDescription>

What it means

Catch-all IllegalStateException from the inline mock maker's constructor: instrumenting the JVM (attaching the Byte Buddy agent, resolving the dispatcher) failed, and the message is assembled from fallback hints (e.g. missing byte-buddy-agent on the class path, or no system Java compiler available to generate the agent) plus a Platform.describe() snapshot. It indicates the inline mock maker could not initialize on this VM, not that a specific mock was bad.

Source

Thrown at mockito-core/src/main/java/org/mockito/internal/creation/bytebuddy/InlineDelegateByteBuddyMockMaker.java:278

                                        "",
                                        "Byte Buddy Agent is available on Maven Central as 'net.bytebuddy:byte-buddy-agent' with the module name 'net.bytebuddy.agent'.",
                                        "Normally, your IDE or build tool (such as Maven or Gradle) should take care of your class path completion but ");
                    } else if (Class.forName("javax.tools.ToolProvider")
                                    .getMethod("getSystemJavaCompiler")
                                    .invoke(null)
                            == null) {
                        detail =
                                "It appears as if you are running on a JRE. Either install a JDK or add JNA to the class path.";
                    } else {
                        detail =
                                "It appears as if your JDK does not supply a working agent attachment mechanism.";
                    }
                } catch (Throwable ignored) {
                    detail =
                            "It appears as if you are running an incomplete JVM installation that might not support all tooling APIs";
                }
            }
            throw new MockitoInitializationException(
                    join(
                            "Could not initialize inline Byte Buddy mock maker.",
                            "",
                            detail,
                            Platform.describe()),
                    INITIALIZATION_ERROR);
        }

        ThreadLocal<Class<?>> currentConstruction = new ThreadLocal<>();
        ThreadLocal<Boolean> isSuspended = ThreadLocal.withInitial(() -> false);
        Predicate<Class<?>> isCallFromSubclassConstructor = StackWalkerChecker.orFallback();
        Predicate<Class<?>> isMockConstruction =
                type -> {
                    if (isSuspended.get()) {
                        return false;
                    } else if ((currentMocking.get() != null
                                    && type.isAssignableFrom(currentMocking.get()))
                            || currentConstruction.get() != null) {

View on GitHub (pinned to 5a676bcd9e)

Solutions

  1. Add the 'net.bytebuddy:byte-buddy-agent' dependency (module name 'net.bytebuddy.agent') matching your byte-buddy version
  2. Start the JVM with '-javaagent:byte-buddy-agent.jar' so self-attach is not needed
  3. Upgrade Mockito and Byte Buddy to versions supporting your JDK
  4. If the runtime lacks the instrumentation API (e.g. some restricted JREs), switch to mockito-core's subclass mock maker via '--mock-maker subclass' or the mock-maker-subclass extension
Defensive patterns

Strategy: fallback

When it happens

Trigger: Thrown at mockito-core/src/main/java/org/mockito/internal/creation/bytebuddy/InlineDelegateByteBuddyMockMaker.java:278 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of mockito/mockito@5a676bcd9e (2026-09-05). Data as JSON: /api/errors/f8103131f1774946. Report an issue: GitHub.