Activiti/Activiti · error · ActivitiException
couldn't find constructor for
Error message
couldn't find constructor for ${className} with args ${args} What it means
ReflectUtil.instantiate(String className, Object[] args) throws ActivitiException when no declared constructor of the class matches the given argument types. It is thrown before any instantiation is attempted.
Solutions
- Align the args array with an existing constructor's exact parameter types (use wrappers for primitives)
- Check the className is the intended class and inspect its declared constructors
- If using XML/Spring wiring, pass constructor args via the framework instead of Object[]
Example fix
// before
ReflectUtil.instantiate("com.acme.MyDelegate", new Object[]{"cfg"}); // ctor takes int
// after
ReflectUtil.instantiate("com.acme.MyDelegate", new Object[]{42}); Defensive patterns
Strategy: validation
Validate before calling
boolean ctorExists = java.util.Arrays.stream(clazz.getDeclaredConstructors()).anyMatch(c -> c.getParameterCount() == args.length);
Try / catch
try { Object o = ReflectUtil.instantiate(className, args); } catch (ActivitiException e) { throw new IllegalArgumentException("No matching constructor for " + className, e); } Prevention
- Match arg count and exact types (wrappers for primitives) to a declared constructor
- Keep BPMN activiti:class config in sync with constructor signatures
- Pass null-typed args deliberately; findMatchingConstructor matches by runtime type
When it happens
Trigger: Calling ReflectUtil.instantiate(className, args) where the argument count/types don't match any declared constructor, including null args or primitive-vs-wrapper mismatches.
Common situations: Misconfigured delegate/expression class names in process definitions (activiti:class) with constructor-arg mismatch; refactoring a constructor signature while XML config still passes old arguments.
Related errors
- couldn't find constructor for " + className + " with args "…
- businessCalendars can not be null
- commentId is null
- Could not set field
- Error while evaluating expression:
AI-assisted analysis of Activiti/Activiti@56435b1a97 (2026-09-09).
Data as JSON: /api/errors/b943a7b765cbe4c3.
Report an issue: GitHub.
Appendix: source
Thrown at activiti-core/activiti-engine/src/main/java/org/activiti/engine/impl/util/ReflectUtil.java:238
private static Method findMethod(Class<? extends Object> clazz, String methodName, Object[] args) {
for (Method method : clazz.getDeclaredMethods()) {
// TODO add parameter matching
if (method.getName().equals(methodName) && matches(method.getParameterTypes(), args)) {
return method;
}
}
Class<?> superClass = clazz.getSuperclass();
if (superClass != null) {
return findMethod(superClass, methodName, args);
}
return null;
}
public static Object instantiate(String className, Object[] args) {
Class<?> clazz = loadClass(className);
Constructor<?> constructor = findMatchingConstructor(clazz, args);
if (constructor == null) {
throw new ActivitiException("couldn't find constructor for " + className + " with args " + asList(args));
}
try {
return constructor.newInstance(args);
} catch (Exception e) {
throw new ActivitiException("couldn't find constructor for " + className + " with args " + asList(args), e);
}
}
@SuppressWarnings({ "unchecked", "rawtypes" })
private static <T> Constructor<T> findMatchingConstructor(Class<T> clazz, Object[] args) {
for (Constructor constructor : clazz.getDeclaredConstructors()) {
// cannot use <?> or <T> due to JDK 5/6 incompatibility
if (matches(constructor.getParameterTypes(), args)) {
return constructor;
}
}
return null;
}View on GitHub (pinned to 56435b1a97)