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
- Use a concrete class instead of an interface for the method-reference target, so SerializedLambda resolution applies.
- Ensure the lambda/method-reference is serializable (declared on a Serializable-capable interface) if you must use SerializedLambda resolution.
- Avoid static method references for interface-typed rules; refactor to an instance reference on a concrete class.
- 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
- Use concrete classes for method-reference entitlement rules.
- Make functional interfaces Serializable if you rely on SerializedLambda resolution.
- Avoid static method references on interface types.
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
- Error occurred when inspecting class: {}
- Proxy fallback only supports instance method references; no
- Method reference passed to 'calling()' does not belong to {}
- No constructor found on {} with parameter types {}
- Path [{}] is already exclusive to [{}]{}, cannot add exclusi
AI-assisted analysis of elastic/elasticsearch@db6a809a66 (2026-08-12).
Data as JSON: /api/errors/5620a94378a3b10c.
Report an issue: GitHub.