{"record":{"id":"8c83f5070ed2b7ef","repo":"elastic/elasticsearch","slug":"function-reference-s-new-d-matching-s-s","errorCode":null,"errorMessage":"function reference [%s::new/%d] matching [%s, %s/%d] not found","messagePattern":"function reference \\[(.+?)::new/(.+?)\\] matching \\[(.+?), (.+?)/(.+?)\\] not found","errorType":"exception","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"modules/lang-painless/src/main/java/org/elasticsearch/painless/FunctionRef.java","lineNumber":146,"sourceCode":"                delegateClassName = CLASS_NAME;\n                isDelegateInterface = false;\n                isDelegateAugmented = false;\n                delegateInvokeType = needsScriptInstance ? H_INVOKEVIRTUAL : H_INVOKESTATIC;\n                delegateMethodName = localFunction.getMangledName();\n                delegateMethodType = localFunction.getMethodType();\n                delegateInjections = new Object[0];\n\n                delegateMethodReturnType = localFunction.getReturnType();\n                delegateMethodParameters = localFunction.getTypeParameters();\n            } else if (\"new\".equals(methodName)) {\n                if (numberOfCaptures != 0) {\n                    throw new IllegalStateException(\"internal error\");\n                }\n\n                PainlessConstructor painlessConstructor = painlessLookup.lookupPainlessConstructor(typeName, interfaceTypeParametersSize);\n\n                if (painlessConstructor == null) {\n                    throw new IllegalArgumentException(\n                        Strings.format(\n                            \"function reference [%s::new/%d] matching [%s, %s/%d] not found\",\n                            typeName,\n                            interfaceTypeParametersSize,\n                            targetClassName,\n                            interfaceMethodName,\n                            interfaceTypeParametersSize\n                        )\n                    );\n                }\n\n                delegateClassName = painlessConstructor.javaConstructor().getDeclaringClass().getName();\n                isDelegateInterface = false;\n                isDelegateAugmented = false;\n                delegateInvokeType = H_NEWINVOKESPECIAL;\n                delegateMethodName = PainlessLookupUtility.CONSTRUCTOR_NAME;\n                delegateMethodType = painlessConstructor.methodType();\n                delegateInjections = new Object[0];","sourceCodeStart":128,"sourceCodeEnd":164,"githubUrl":"https://github.com/elastic/elasticsearch/blob/db6a809a667c081ca1dc7500389d26975573215f/modules/lang-painless/src/main/java/org/elasticsearch/painless/FunctionRef.java#L128-L164","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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."],"exampleFix":"// before\nFunction<String, StringBuilder> f = StringBuilder::new;  // if String-arg ctor not whitelisted\n// after\nSupplier<StringBuilder> f = StringBuilder::new;  // use no-arg ctor","handlingStrategy":"validation","validationCode":"// Confirm the class is whitelisted and has a constructor with matching arity:\n// // Check Painless allowed classes list for the target class and constructor","typeGuard":null,"tryCatchPattern":null,"preventionTips":["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."],"tags":["painless","elasticsearch","constructor-reference","whitelist","compile-time"],"analyzedSha":"db6a809a667c081ca1dc7500389d26975573215f","analyzedAt":"2026-08-12T01:39:14.192Z","schemaVersion":2},"datasetVersion":"2026-08-12T11:17:21.771Z"}