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
- Inspect the target class's declared constructors: 'javap <class>' and match the parameter types exactly.
- Correct the parameter type list passed to the constructor rule to match an existing constructor.
- If the constructor was changed, update the entitlement rule to the new signature.
- 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
- Cross-check constructor signatures with 'javap' before writing the rule.
- When a constructor signature changes, update dependent entitlement rules in the same commit.
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
- Error occurred when inspecting class: {}; SerializedLambda r
- Error occurred when inspecting class: {}
- Proxy fallback only supports instance method references; no
- Method reference passed to 'calling()' does not belong to {}
- Path [{}] is already exclusive to [{}]{}, cannot add exclusi
AI-assisted analysis of elastic/elasticsearch@db6a809a66 (2026-08-12).
Data as JSON: /api/errors/6916794ba94f2537.
Report an issue: GitHub.