{"record":{"id":"45cdddfeaeb87d41","repo":"flowable/flowable-engine","slug":"couldn-t-find-constructor-for-classname-with-ar-45cddd","errorCode":null,"errorMessage":"couldn't find constructor for ${className} with args ${Arrays.asList(args)}","messagePattern":"couldn't find constructor for (.+?) with args (.+?)","errorType":"exception","errorClass":"org.activiti.engine.ActivitiException","httpStatus":null,"severity":"error","filePath":"modules/flowable5-engine/src/main/java/org/activiti/engine/impl/util/ReflectUtil.java","lineNumber":232,"sourceCode":"        for (Method method : clazz.getDeclaredMethods()) {\n            // TODO add parameter matching\n            if (method.getName().equals(methodName)\n                    && 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 \" + Arrays.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 \" + Arrays.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()) { // 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    }\n","sourceCodeStart":214,"sourceCodeEnd":250,"githubUrl":"https://github.com/flowable/flowable-engine/blob/d6d39ce1c69ff244f2d9dc6af756a9b95e865586/modules/flowable5-engine/src/main/java/org/activiti/engine/impl/util/ReflectUtil.java#L214-L250","documentation":"ReflectUtil.instantiate(className, args) throws this when no declared constructor of the loaded class matches the supplied argument list (findMatchingConstructor returned null). No cause is chained — the constructor simply wasn't found. It signals a signature mismatch between what the caller passes and what the class declares.","triggerScenarios":"ReflectUtil.instantiate(\"com.example.Foo\", new Object[]{\"a\", 1}) where Foo has no constructor accepting those argument types/count (matching is strict, incl. primitives vs wrappers).","commonSituations":"Configuring a custom class (e.g. variable type, session factory) with constructor args that don't fit; upgrading the library where the class's constructor changed; passing nulls that can't disambiguate the constructor.","solutions":["Verify the class exposes a constructor matching the exact arg count/types","Add or change the configured constructor args in your configuration","Add a matching constructor to the target class","Check for primitive-vs-wrapper and null ambiguity in argument matching"],"exampleFix":"// before\nReflectUtil.instantiate(\"com.acme.MyType\", new Object[]{\"cfg\"}); // MyType has only MyType(String, int)\n// after\nReflectUtil.instantiate(\"com.acme.MyType\", new Object[]{\"cfg\", 42});","handlingStrategy":"validation","validationCode":"// verify a matching constructor exists before instantiate\nboolean matches = false;\nfor (Constructor<?> c : Class.forName(className).getDeclaredConstructors()) {\n  if (c.getParameterCount() == args.length) { matches = true; break; }\n}\nif (!matches) throw new IllegalStateException(\"no constructor of \" + className + \" takes \" + args.length + \" args\");","typeGuard":"boolean instantiableWith(Class<?> clazz, Object[] args) {\n  for (Constructor<?> c : clazz.getDeclaredConstructors()) {\n    if (c.getParameterCount() == args.length) return true;\n  }\n  return false;\n}","tryCatchPattern":"try {\n  Object o = ReflectUtil.instantiate(className, args);\n} catch (ActivitiException e) {\n  throw new IllegalStateException(\"check constructor signature of \" + className, e);\n}","preventionTips":["Keep configured classes with a no-arg or args-matching constructor","Re-check constructor signatures after engine upgrades","Avoid primitives/wrapper mismatches in constructor args","Test custom class wiring at startup, not at first use"],"tags":["reflection","constructor","java"],"backgroundTag":"invalid-constructor-argument","analyzedSha":"d6d39ce1c69ff244f2d9dc6af756a9b95e865586","analyzedAt":"2026-09-11T06:41:19.413Z","contentChangedAt":"2026-09-11T06:41:19.413Z","schemaVersion":2},"datasetVersion":"2026-09-14T11:17:12.474Z"}