{"record":{"id":"5620a94378a3b10c","repo":"elastic/elasticsearch","slug":"error-occurred-when-inspecting-class-serializ","errorCode":null,"errorMessage":"Error occurred when inspecting class: {}; SerializedLambda resolution failed and proxy fallback failed","messagePattern":"Error occurred when inspecting class: (.+?); SerializedLambda resolution failed and proxy fallback failed","errorType":"exception","errorClass":"RuntimeException","httpStatus":null,"severity":"error","filePath":"libs/entitlement/src/main/java/org/elasticsearch/entitlement/rules/ClassMethodBuilder.java","lineNumber":1102,"sourceCode":"            arg1.getRawType(),\n            arg2.getRawType(),\n            arg3.getRawType(),\n            arg4.getRawType()\n        );\n        return new MethodRuleBuilder.MethodRuleBuilder5<>(registry, clazz, methodKey);\n    }\n\n    @SuppressForbidden(reason = \"relies on reflection\")\n    private static MethodKey resolveMethodReference(Class<?> clazz, Object ref, Class<?>... args) {\n        try {\n            return resolveMethodReferenceViaSerializedLambda(clazz, ref, args);\n        } catch (Exception e) {\n            if (clazz.isInterface()) {\n                try {\n                    return resolveMethodReferenceViaProxy(clazz, ref, args);\n                } catch (Exception proxyException) {\n                    proxyException.addSuppressed(e);\n                    throw new RuntimeException(\n                        \"Error occurred when inspecting class: \"\n                            + clazz.getName()\n                            + \"; SerializedLambda resolution failed and proxy fallback failed\",\n                        proxyException\n                    );\n                }\n            }\n            throw new RuntimeException(\"Error occurred when inspecting class: \" + clazz.getName(), e);\n        }\n    }\n\n    @SuppressForbidden(reason = \"relies on reflection\")\n    private static MethodKey resolveMethodReferenceViaSerializedLambda(Class<?> clazz, Object ref, Class<?>... args) throws Exception {\n        Method writeReplace = ref.getClass().getDeclaredMethod(\"writeReplace\");\n        writeReplace.setAccessible(true);\n\n        SerializedLambda serialized = (SerializedLambda) writeReplace.invoke(ref);\n        String className = serialized.getImplClass();","sourceCodeStart":1084,"sourceCodeEnd":1120,"githubUrl":"https://github.com/elastic/elasticsearch/blob/db6a809a667c081ca1dc7500389d26975573215f/libs/entitlement/src/main/java/org/elasticsearch/entitlement/rules/ClassMethodBuilder.java#L1084-L1120","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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)."],"exampleFix":"// before: interface-typed static method reference\npolicy.calling(MyInterface::staticHelper).isAllowed(...);\n\n// after: instance reference on a concrete class\npolicy.calling(MyConcreteClass::instanceHelper).isAllowed(...);","handlingStrategy":"validation","validationCode":"// Before registering a rule, prefer concrete classes and serializable interfaces\nif (targetType.isInterface() && !java.io.Serializable.class.isAssignableFrom(targetType)) {\n  throw new IllegalArgumentException(\"Use a concrete class or Serializable interface for the method reference\");\n}","typeGuard":"boolean isResolvableInterface(Class<?> c) {\n  return c.isInterface() && java.io.Serializable.class.isAssignableFrom(c);\n}","tryCatchPattern":null,"preventionTips":["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."],"tags":["entitlement","method-reference","reflection","lambda","policy"],"analyzedSha":"db6a809a667c081ca1dc7500389d26975573215f","analyzedAt":"2026-08-12T01:39:14.192Z","schemaVersion":2},"datasetVersion":"2026-08-12T12:17:08.281Z"}