elastic/elasticsearch · error · RuntimeException

Error occurred when inspecting class: {}; SerializedLambda r

Error message

Error occurred when inspecting class: {}; SerializedLambda resolution failed and proxy fallback failed

What it means

Thrown by ClassMethodBuilder.resolveMethodReference when BOTH the primary SerializedLambda resolution AND the interface-proxy fallback fail for an interface type. The method-reference passed to an entitlement rule (e.g. 'calling(...)') could not be resolved to a concrete method by either technique. The original SerializedLambda error is suppressed on the proxy exception which becomes the cause.

Source

Thrown at libs/entitlement/src/main/java/org/elasticsearch/entitlement/rules/ClassMethodBuilder.java:1102

            arg1.getRawType(),
            arg2.getRawType(),
            arg3.getRawType(),
            arg4.getRawType()
        );
        return new MethodRuleBuilder.MethodRuleBuilder5<>(registry, clazz, methodKey);
    }

    @SuppressForbidden(reason = "relies on reflection")
    private static MethodKey resolveMethodReference(Class<?> clazz, Object ref, Class<?>... args) {
        try {
            return resolveMethodReferenceViaSerializedLambda(clazz, ref, args);
        } catch (Exception e) {
            if (clazz.isInterface()) {
                try {
                    return resolveMethodReferenceViaProxy(clazz, ref, args);
                } catch (Exception proxyException) {
                    proxyException.addSuppressed(e);
                    throw new RuntimeException(
                        "Error occurred when inspecting class: "
                            + clazz.getName()
                            + "; SerializedLambda resolution failed and proxy fallback failed",
                        proxyException
                    );
                }
            }
            throw new RuntimeException("Error occurred when inspecting class: " + clazz.getName(), e);
        }
    }

    @SuppressForbidden(reason = "relies on reflection")
    private static MethodKey resolveMethodReferenceViaSerializedLambda(Class<?> clazz, Object ref, Class<?>... args) throws Exception {
        Method writeReplace = ref.getClass().getDeclaredMethod("writeReplace");
        writeReplace.setAccessible(true);

        SerializedLambda serialized = (SerializedLambda) writeReplace.invoke(ref);
        String className = serialized.getImplClass();

View on GitHub (pinned to db6a809a66)

Solutions

  1. Use a concrete class instead of an interface for the method-reference target, so SerializedLambda resolution applies.
  2. Ensure the lambda/method-reference is serializable (declared on a Serializable-capable interface) if you must use SerializedLambda resolution.
  3. Avoid static method references for interface-typed rules; refactor to an instance reference on a concrete class.
  4. Inspect the suppressed SerializedLambda exception for the root cause (e.g. missing writeReplace).

Example fix

// before: interface-typed static method reference
policy.calling(MyInterface::staticHelper).isAllowed(...);

// after: instance reference on a concrete class
policy.calling(MyConcreteClass::instanceHelper).isAllowed(...);
Defensive patterns

Strategy: validation

Validate before calling

// Before registering a rule, prefer concrete classes and serializable interfaces
if (targetType.isInterface() && !java.io.Serializable.class.isAssignableFrom(targetType)) {
  throw new IllegalArgumentException("Use a concrete class or Serializable interface for the method reference");
}

Type guard

boolean isResolvableInterface(Class<?> c) {
  return c.isInterface() && java.io.Serializable.class.isAssignableFrom(c);
}

Prevention

When it happens

Trigger: resolveMethodReferenceViaSerializedLambda throws (no writeReplace, non-serializable lambda, etc.), clazz.isInterface() is true, then resolveMethodReferenceViaProxy also throws. The combined failure is reported with both suppressed and cause.

Common situations: Defining an entitlement rule with a method reference on an interface whose lambda is not serializable and whose proxy invocation does not record a method; a static method reference on an interface type where the proxy fallback cannot capture it; an exotic functional interface shape the resolver does not handle.

Related errors


AI-assisted analysis of elastic/elasticsearch@db6a809a66 (2026-08-12). Data as JSON: /api/errors/5620a94378a3b10c. Report an issue: GitHub.