{"record":{"id":"b943a7b765cbe4c3","repo":"Activiti/Activiti","slug":"couldn-t-find-constructor-for-classname-with-ar","errorCode":null,"errorMessage":"couldn't find constructor for ${className} with args ${args}","messagePattern":"couldn't find constructor for (.+?) with args (.+?)","errorType":"exception","errorClass":"ActivitiException","httpStatus":null,"severity":"error","filePath":"activiti-core/activiti-engine/src/main/java/org/activiti/engine/impl/util/ReflectUtil.java","lineNumber":238,"sourceCode":"    private static Method findMethod(Class<? extends Object> clazz, String methodName, Object[] args) {\n        for (Method method : clazz.getDeclaredMethods()) {\n            // TODO add parameter matching\n            if (method.getName().equals(methodName) && matches(method.getParameterTypes(), args)) {\n                return method;\n            }\n        }\n        Class<?> superClass = clazz.getSuperclass();\n        if (superClass != null) {\n            return findMethod(superClass, methodName, args);\n        }\n        return null;\n    }\n\n    public static Object instantiate(String className, Object[] args) {\n        Class<?> clazz = loadClass(className);\n        Constructor<?> constructor = findMatchingConstructor(clazz, args);\n        if (constructor == null) {\n            throw new ActivitiException(\"couldn't find constructor for \" + className + \" with args \" + asList(args));\n        }\n        try {\n            return constructor.newInstance(args);\n        } catch (Exception e) {\n            throw new ActivitiException(\"couldn't find constructor for \" + className + \" with args \" + asList(args), e);\n        }\n    }\n\n    @SuppressWarnings({ \"unchecked\", \"rawtypes\" })\n    private static <T> Constructor<T> findMatchingConstructor(Class<T> clazz, Object[] args) {\n        for (Constructor constructor : clazz.getDeclaredConstructors()) {\n            // cannot use <?> or <T> due to JDK 5/6 incompatibility\n            if (matches(constructor.getParameterTypes(), args)) {\n                return constructor;\n            }\n        }\n        return null;\n    }","sourceCodeStart":220,"sourceCodeEnd":256,"githubUrl":"https://github.com/Activiti/Activiti/blob/56435b1a97deeafdc09dd40074b056c89fba5a8a/activiti-core/activiti-engine/src/main/java/org/activiti/engine/impl/util/ReflectUtil.java#L220-L256","documentation":"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.","triggerScenarios":"Calling ReflectUtil.instantiate(className, args) where the argument count/types don't match any declared constructor, including null args or primitive-vs-wrapper mismatches.","commonSituations":"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.","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[]"],"exampleFix":"// before\nReflectUtil.instantiate(\"com.acme.MyDelegate\", new Object[]{\"cfg\"}); // ctor takes int\n// after\nReflectUtil.instantiate(\"com.acme.MyDelegate\", new Object[]{42});","handlingStrategy":"validation","validationCode":"boolean ctorExists = java.util.Arrays.stream(clazz.getDeclaredConstructors()).anyMatch(c -> c.getParameterCount() == args.length);","typeGuard":null,"tryCatchPattern":"try { Object o = ReflectUtil.instantiate(className, args); } catch (ActivitiException e) { throw new IllegalArgumentException(\"No matching constructor for \" + className, e); }","preventionTips":["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"],"tags":["reflection","constructor","activiti"],"backgroundTag":"invalid-constructor-argument","analyzedSha":"56435b1a97deeafdc09dd40074b056c89fba5a8a","analyzedAt":"2026-09-09T21:00:06.703Z","contentChangedAt":"2026-09-09T21:00:06.703Z","schemaVersion":2},"datasetVersion":"2026-09-17T15:17:12.973Z"}