elastic/elasticsearch · error · IllegalArgumentException
function reference [%s::new/%d] matching [%s, %s/%d] not fou
Error message
function reference [%s::new/%d] matching [%s, %s/%d] not found
What it means
FunctionRef.create throws this IllegalArgumentException at compile time when a constructor reference 'Type::new' cannot resolve a whitelisted Painless constructor with the required argument count. The compiler calls lookupPainlessConstructor(typeName, interfaceTypeParametersSize); if null, no constructor of that class taking exactly that many parameters is registered in the Painless allowlist. Constructor references in Painless can only target classes and constructors explicitly whitelisted.
Source
Thrown at modules/lang-painless/src/main/java/org/elasticsearch/painless/FunctionRef.java:146
delegateClassName = CLASS_NAME;
isDelegateInterface = false;
isDelegateAugmented = false;
delegateInvokeType = needsScriptInstance ? H_INVOKEVIRTUAL : H_INVOKESTATIC;
delegateMethodName = localFunction.getMangledName();
delegateMethodType = localFunction.getMethodType();
delegateInjections = new Object[0];
delegateMethodReturnType = localFunction.getReturnType();
delegateMethodParameters = localFunction.getTypeParameters();
} else if ("new".equals(methodName)) {
if (numberOfCaptures != 0) {
throw new IllegalStateException("internal error");
}
PainlessConstructor painlessConstructor = painlessLookup.lookupPainlessConstructor(typeName, interfaceTypeParametersSize);
if (painlessConstructor == null) {
throw new IllegalArgumentException(
Strings.format(
"function reference [%s::new/%d] matching [%s, %s/%d] not found",
typeName,
interfaceTypeParametersSize,
targetClassName,
interfaceMethodName,
interfaceTypeParametersSize
)
);
}
delegateClassName = painlessConstructor.javaConstructor().getDeclaringClass().getName();
isDelegateInterface = false;
isDelegateAugmented = false;
delegateInvokeType = H_NEWINVOKESPECIAL;
delegateMethodName = PainlessLookupUtility.CONSTRUCTOR_NAME;
delegateMethodType = painlessConstructor.methodType();
delegateInjections = new Object[0];View on GitHub (pinned to db6a809a66)
Solutions
- Confirm the class is whitelisted for construction in Painless (check the allowed classes list).
- Adjust the functional interface so its parameter count matches a whitelisted constructor arity.
- Replace the constructor reference with an explicit lambda that calls the constructor with the correct arguments.
Example fix
// before Function<String, StringBuilder> f = StringBuilder::new; // if String-arg ctor not whitelisted // after Supplier<StringBuilder> f = StringBuilder::new; // use no-arg ctor
Defensive patterns
Strategy: validation
Validate before calling
// Confirm the class is whitelisted and has a constructor with matching arity: // // Check Painless allowed classes list for the target class and constructor
Prevention
- Verify the target class is whitelisted in Painless before using ::new.
- Match constructor arity to the functional interface parameter count.
- Fall back to an explicit lambda calling the constructor.
When it happens
Trigger: Writing 'HashMap::new' or 'StringBuilder::new' where the class is not whitelisted, or the constructor arity does not match the functional interface's parameter count. For example, 'Supplier<List> s = ArrayList::new;' works (no-arg constructor) but 'Function<Integer, ArrayList> f = ArrayList::new;' fails if the single-int-arg constructor is not whitelisted.
Common situations: Referencing a Java class not permitted in Painless scripts. Mismatched constructor arity between the functional interface and available constructors. Class present in Java but absent from the Painless whitelist.
Related errors
- function reference [%s::%s/%d] matching [%s, %s/%d] not foun
- Cannot apply operator [{}] to type [{}]
- Cannot apply operator [{}] to types [{}] and [{}]
- Cannot cast {} to {}
- cannot convert function reference [%s::%s] to a non-function
AI-assisted analysis of elastic/elasticsearch@db6a809a66 (2026-08-12).
Data as JSON: /api/errors/8c83f5070ed2b7ef.
Report an issue: GitHub.