{"record":{"id":"66a0ab01dc4cc668","repo":"elastic/elasticsearch","slug":"cannot-convert-function-reference-s-s-to-a-no","errorCode":null,"errorMessage":"cannot convert function reference [%s::%s] to a non-functional interface [%s]","messagePattern":"cannot convert function reference \\[(.+?)::(.+?)\\] to a non-functional interface \\[(.+?)\\]","errorType":"exception","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"modules/lang-painless/src/main/java/org/elasticsearch/painless/FunctionRef.java","lineNumber":78,"sourceCode":"        String methodName,\n        int numberOfCaptures,\n        Map<String, Object> constants,\n        boolean needsScriptInstance\n    ) {\n\n        Objects.requireNonNull(painlessLookup);\n        Objects.requireNonNull(targetClass);\n        Objects.requireNonNull(typeName);\n        Objects.requireNonNull(methodName);\n\n        String targetClassName = PainlessLookupUtility.typeToCanonicalTypeName(targetClass);\n        PainlessMethod interfaceMethod;\n\n        try {\n            interfaceMethod = painlessLookup.lookupFunctionalInterfacePainlessMethod(targetClass);\n\n            if (interfaceMethod == null) {\n                throw new IllegalArgumentException(\n                    Strings.format(\n                        \"cannot convert function reference [%s::%s] to a non-functional interface [%s]\",\n                        typeName,\n                        methodName,\n                        targetClassName\n                    )\n                );\n            }\n\n            String interfaceMethodName = interfaceMethod.javaMethod().getName();\n            MethodType interfaceMethodType = interfaceMethod.methodType().dropParameterTypes(0, 1);\n            String delegateClassName;\n            boolean isDelegateInterface;\n            boolean isDelegateAugmented;\n            int delegateInvokeType;\n            String delegateMethodName;\n            MethodType delegateMethodType;\n            Object[] delegateInjections;","sourceCodeStart":60,"sourceCodeEnd":96,"githubUrl":"https://github.com/elastic/elasticsearch/blob/db6a809a667c081ca1dc7500389d26975573215f/modules/lang-painless/src/main/java/org/elasticsearch/painless/FunctionRef.java#L60-L96","documentation":"FunctionRef.create throws this IllegalArgumentException at compile time when a Painless method-reference expression (Type::method) targets a class that is not a functional interface. Painless method references can only be converted to types that declare exactly one abstract method (a SAM type). The compiler calls lookupFunctionalInterfacePainlessMethod; if it returns null, the target has zero or multiple abstract methods and the reference cannot be bound.","triggerScenarios":"Writing a Painless method reference where the target type is a marker interface, an abstract class with multiple methods, or a concrete class: 'Consumer c = List::size;' where List is not whitelisted as a functional interface, or assigning to a type Painless does not recognize as functional.","commonSituations":"Using method references with interfaces that Painless's whitelist does not mark as functional. Attempting to use a Java interface not allowed in scripts. Confusing a method reference target with a regular class type.","solutions":["Ensure the target type is a single-abstract-method interface (e.g. java.util.function.Function, Consumer, Predicate) that is whitelisted in Painless.","Replace the method reference with an explicit lambda that implements the interface.","Check the Painless allowlist for the interface; if it is missing, the method reference will not compile."],"exampleFix":"// before\nSomeClass ref = String::length;  // SomeClass is not a functional interface\n// after\nFunction<String, Integer> ref = String::length;","handlingStrategy":"validation","validationCode":"// Ensure the target type is a single-method interface before using a method reference:\n// // java.util.function.Function, Consumer, Predicate, Supplier are valid functional interfaces","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Only assign method references to functional interfaces (single abstract method).","Check the Painless allowlist for the interface.","Prefer explicit lambdas when unsure about functional interface status."],"tags":["painless","elasticsearch","method-reference","functional-interface","compile-time"],"analyzedSha":"db6a809a667c081ca1dc7500389d26975573215f","analyzedAt":"2026-08-12T01:39:14.192Z","schemaVersion":2},"datasetVersion":"2026-08-12T08:17:17.861Z"}