elastic/elasticsearch · error · IllegalArgumentException

type [{}] not found

Error message

type [{}] not found

What it means

Def.lookupReference (lambda reference binding) first resolves the declared functional-interface class name through painlessLookup.canonicalTypeNameToType. If that map has no entry for the given interfaceClass string (the type was never registered/whitelisted), it throws 'type not found' with the unresolved name. This precedes any method resolution and indicates the interface type itself is unknown to the Painless type system.

Source

Thrown at modules/lang-painless/src/main/java/org/elasticsearch/painless/Def.java:491

     * Returns an implementation of interfaceClass that calls receiverClass.name
     * <p>
     * This is just like LambdaMetaFactory, only with a dynamic type. The interface type is known,
     * so we simply need to lookup the matching implementation method based on receiver type.
     */
    static MethodHandle lookupReference(
        PainlessLookup painlessLookup,
        FunctionTable functions,
        Map<String, Object> constants,
        MethodHandles.Lookup methodHandlesLookup,
        String interfaceClass,
        Class<?> receiverClass,
        String name,
        boolean chargesAllocation
    ) throws Throwable {

        Class<?> interfaceType = painlessLookup.canonicalTypeNameToType(interfaceClass);
        if (interfaceType == null) {
            throw new IllegalArgumentException("type [" + interfaceClass + "] not found");
        }
        PainlessMethod interfaceMethod = painlessLookup.lookupFunctionalInterfacePainlessMethod(interfaceType);
        if (interfaceMethod == null) {
            throw new IllegalArgumentException("Class [" + interfaceClass + "] is not a functional interface");
        }
        int arity = interfaceMethod.typeParameters().size();
        PainlessMethod implMethod = painlessLookup.lookupRuntimePainlessMethod(receiverClass, name, arity);
        if (implMethod == null) {
            throw new IllegalArgumentException(
                "dynamic method [" + typeToCanonicalTypeName(receiverClass) + ", " + name + "/" + arity + "] not found"
            );
        }

        // Charging def-receiver ref: the script was over-captured (receiver type unknown, so no pre-filter). Charge only if
        // the resolved target has an estimator; either way lookupReferenceInternal appends the script and drops it.
        return lookupReferenceInternal(
            painlessLookup,
            functions,

View on GitHub (pinned to db6a809a66)

Solutions

  1. Use a standard whitelisted functional interface from java.util.function (Function, Consumer, Predicate, etc.) that Painless knows about.
  2. Verify the exact canonical name spelling matches a registered type.
  3. If a custom interface is required, register it in the painless allowlist via a plugin.

Example fix

// before
// references a non-whitelisted interface type
// after
// use java.util.function.Function which is whitelisted
Defensive patterns

Strategy: type-guard

Type guard

// Restrict lambda targets to whitelisted java.util.function types in script authoring tooling.
// Maintain an allow-set: [Function, Consumer, Predicate, Supplier, BiFunction, ...]

Try / catch

// On ScriptException matching 'type [...] not found', tell the author the interface is not whitelisted and suggest a standard functional interface.

Prevention

When it happens

Trigger: A Painless script uses a method-reference or lambda whose declared interface type is not registered in the Painless allowlist — e.g. referencing a custom or non-whitelisted functional interface (java.util.function.X from a non-JDK package, or a JDK functional interface excluded by the allowlist).

Common situations: Plugin code expecting a custom functional interface to be available. Using a functional interface added in a newer JDK than the allowlist covers. Typo in the interface canonical name.

Related errors


AI-assisted analysis of elastic/elasticsearch@db6a809a66 (2026-08-12). Data as JSON: /api/errors/45dadb05ab534a4f. Report an issue: GitHub.