mockito/mockito · error · MockitoException

Failed to access default method or invoked method with illeg

Error message

Failed to access default method or invoked method with illegal arguments

Method " + serializableMethod.getJavaMethod() + " could not be delegated, this is not supposed to happen
" + Platform.describe()

What it means

Error "Failed to access default method or invoked method with illegal arguments Method " + serializableMethod.getJavaMethod() + " could not be delegated, this is not supposed to happen " + Platform.describe()" thrown in mockito/mockito.

Source

Thrown at mockito-core/src/main/java/org/mockito/internal/creation/proxy/InvokeDefaultProxy.java:60

        private InvokeDefaultRealMethod(Object proxy, Method method, Object[] args) {
            this.proxy = proxy;
            this.serializableMethod = new SerializableMethod(method);
            this.args = args;
        }

        @Override
        public boolean isInvokable() {
            return true;
        }

        @Override
        public Object invoke() throws Throwable {
            try {
                return invokeDefault.invoke(null, proxy, serializableMethod.getJavaMethod(), args);
            } catch (InvocationTargetException e) {
                throw e.getTargetException();
            } catch (IllegalAccessException | IllegalArgumentException e) {
                throw new MockitoException(
                        join(
                                "Failed to access default method or invoked method with illegal arguments",
                                "",
                                "Method "
                                        + serializableMethod.getJavaMethod()
                                        + " could not be delegated, this is not supposed to happen",
                                Platform.describe()),
                        e);
            }
        }
    }
}

View on GitHub (pinned to 5a676bcd9e)

Solutions

  1. Check that the reflected Method passed to the proxy matches an interface default method of that proxy
  2. Pass argument arrays whose types match the method's parameter types
  3. Upgrade mockito-core if on an older version, since proxy default-method invocation handling has been improved
  4. If the JVM offers non-standard MethodHandles.Lookup behavior, run tests on a standard JDK or update Mockito/byte-buddy
Defensive patterns

Strategy: try-catch

When it happens

Trigger: Thrown at mockito-core/src/main/java/org/mockito/internal/creation/proxy/InvokeDefaultProxy.java:60 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/955a25bad55bffec. Report an issue: GitHub.