elastic/elasticsearch · error · IllegalArgumentException

No constructor found on {} with parameter types {}

Error message

No constructor found on {} with parameter types {}

What it means

Thrown by ClassMethodBuilder.validateConstructorExists when the requested class does not declare a constructor with the given parameter types. The entitlement rule builder needs the exact constructor to instrument it; absence means the rule references a constructor signature that does not exist (after primitive boxing resolution).

Source

Thrown at libs/entitlement/src/main/java/org/elasticsearch/entitlement/rules/ClassMethodBuilder.java:1205

        }
    }

    @SuppressForbidden(reason = "relies on reflection")
    private static Class<?> resolveDeclaringClass(Class<?> clazz, String methodName, Class<?>... args) throws NoSuchMethodException {
        if ("<init>".equals(methodName)) {
            return clazz;
        }
        Class<?>[] resolvedArgs = Arrays.stream(args).map(TypeUtils::toPrimitive).toArray(Class[]::new);
        return clazz.getMethod(methodName, resolvedArgs).getDeclaringClass();
    }

    @SuppressForbidden(reason = "relies on reflection")
    private static void validateConstructorExists(Class<?> clazz, Class<?>... args) {
        Class<?>[] resolvedArgs = Arrays.stream(args).map(TypeUtils::toPrimitive).toArray(Class[]::new);
        try {
            clazz.getDeclaredConstructor(resolvedArgs);
        } catch (NoSuchMethodException e) {
            throw new IllegalArgumentException(
                "No constructor found on " + clazz.getName() + " with parameter types " + Arrays.stream(args).map(Class::getName).toList(),
                e
            );
        }
    }

    private static MethodKey resolveConstructor(Class<?> clazz, Class<?>... args) {
        validateConstructorExists(clazz, args);
        return new MethodKey(
            clazz.getName().replace(".", "/"),
            "<init>",
            Arrays.stream(args).map(TypeUtils::getParameterTypeName).toList()
        );
    }
}

View on GitHub (pinned to db6a809a66)

Solutions

  1. Inspect the target class's declared constructors: 'javap <class>' and match the parameter types exactly.
  2. Correct the parameter type list passed to the constructor rule to match an existing constructor.
  3. If the constructor was changed, update the entitlement rule to the new signature.
  4. Ensure you reference the correct class (subclass vs superclass constructor confusion).

Example fix

// before: rule references a constructor that does not exist
builder.callingConstructor(MyClass.class, String.class, int.class);
// but MyClass only has (String)

// after: match the real signature
builder.callingConstructor(MyClass.class, String.class);
Defensive patterns

Strategy: validation

Validate before calling

// Confirm the constructor exists before building the rule
Class<?>[] resolved = Arrays.stream(args).map(TypeUtils::toPrimitive).toArray(Class[]::new);
try { clazz.getDeclaredConstructor(resolved); }
catch (NoSuchMethodException e) { throw new IllegalArgumentException("no such constructor", e); }

Type guard

boolean constructorExists(Class<?> clazz, Class<?>... args) {
  try { clazz.getDeclaredConstructor(args); return true; }
  catch (NoSuchMethodException e) { return false; }
}

Prevention

When it happens

Trigger: validateConstructorExists resolves args via TypeUtils.toPrimitive then calls clazz.getDeclaredConstructor(resolvedArgs); if no such constructor exists, NoSuchMethodException is caught and rethrown as IllegalArgumentException naming the class and the original (non-primitive) parameter types.

Common situations: Specifying constructor parameter types that do not match any declared constructor; using wrapper types (Integer) where the constructor takes primitives and the auto-resolution fails; a refactor changed the constructor signature; the wrong class was referenced.

Related errors


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