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

  1. Align the args array with an existing constructor's exact parameter types (use wrappers for primitives)
  2. Check the className is the intended class and inspect its declared constructors
  3. 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

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


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)