elastic/elasticsearch · error · IllegalArgumentException
function reference [%s::%s/%d] matching [%s, %s/%d] not foun
Error message
function reference [%s::%s/%d] matching [%s, %s/%d] not found
What it means
FunctionRef.create throws this IllegalArgumentException at compile time when a method reference 'Type::methodName' cannot resolve any whitelisted Painless method (static or instance) matching the name and arity. The compiler first tries an augmented instance method lookup, then a static method lookup with adjusted arity; if both return null, no accessible method of that class with that name and parameter count exists in the Painless allowlist.
Source
Thrown at modules/lang-painless/src/main/java/org/elasticsearch/painless/FunctionRef.java:191
boolean captured = numberOfCaptures == 1;
PainlessMethod painlessMethod = painlessLookup.lookupPainlessMethod(
typeName,
true,
methodName,
interfaceTypeParametersSize
);
if (painlessMethod == null) {
painlessMethod = painlessLookup.lookupPainlessMethod(
typeName,
false,
methodName,
captured ? interfaceTypeParametersSize : interfaceTypeParametersSize - 1
);
if (painlessMethod == null) {
throw new IllegalArgumentException(
Strings.format(
"function reference [%s::%s/%d] matching [%s, %s/%d] not found",
typeName,
methodName,
interfaceTypeParametersSize,
targetClassName,
interfaceMethodName,
interfaceTypeParametersSize
)
);
}
} else if (captured) {
throw new IllegalArgumentException(
Strings.format(
"cannot use a static method as a function reference [%s::%s/%d] with a non-static captured variable",
typeName,
methodName,
interfaceTypeParametersSizeView on GitHub (pinned to db6a809a66)
Solutions
- Verify the method name is spelled correctly and exists on the referenced class.
- Confirm the class and method are whitelisted in the Painless API (check the allowed methods list for your ES version).
- Adjust the functional interface arity to match the method's parameter count (remember instance methods consume one parameter for the receiver).
Example fix
// before Function<String, String> f = String::reversed; // typo, method is 'reverse' or doesn't exist // after Function<StringBuilder, StringBuilder> f = StringBuilder::reverse;
Defensive patterns
Strategy: validation
Validate before calling
// Verify the method exists and is whitelisted with matching arity: // // Check the Painless API docs for the class's allowed methods
Prevention
- Confirm method name spelling and whitelist status before referencing.
- Account for the receiver parameter when matching instance method arity.
- Use explicit lambdas as a fallback when references fail to resolve.
When it happens
Trigger: Writing 'String::fooBar' where fooBar does not exist or is not whitelisted. Writing 'List::size' when List is not allowed or size is not whitelisted. Mismatched arity: the functional interface expects N parameters but the referenced method has a different count.
Common situations: Typos in method names. Referencing methods on classes not whitelisted in Painless. Methods that exist in Java but are excluded from the Painless API surface for safety. Version differences where a method was removed or renamed.
Related errors
- cannot convert function reference [%s::%s] to a non-function
- function reference [this::%s] matching [%s, %s/%d] not found
- function reference [%s::new/%d] matching [%s, %s/%d] not fou
- cannot use a static method as a function reference [%s::%s/%
- Cannot apply operator [{}] to type [{}]
AI-assisted analysis of elastic/elasticsearch@db6a809a66 (2026-08-12).
Data as JSON: /api/errors/7498412fd9181bde.
Report an issue: GitHub.