{"record":{"id":"9df10ffa9e90d443","repo":"flowable/flowable-engine","slug":"couldn-t-instantiate-class-classname","errorCode":null,"errorMessage":"couldn't instantiate class ${className}","messagePattern":"couldn't instantiate class (.+?)","errorType":"exception","errorClass":"FlowableException","httpStatus":null,"severity":"error","filePath":"modules/flowable-engine-common/src/main/java/org/flowable/common/engine/impl/util/ReflectUtil.java","lineNumber":148,"sourceCode":"            // Try the current Thread context classloader\n            classLoader = Thread.currentThread().getContextClassLoader();\n            url = classLoader.getResource(name);\n            if (url == null) {\n                // Finally, try the classloader for this class\n                classLoader = ReflectUtil.class.getClassLoader();\n                url = classLoader.getResource(name);\n            }\n        }\n\n        return url;\n    }\n\n    public static Object instantiate(String className) {\n        try {\n            Class<?> clazz = loadClass(className);\n            return clazz.getConstructor().newInstance();\n        } catch (Exception e) {\n            throw new FlowableException(\"couldn't instantiate class \" + className, e);\n        }\n    }\n\n    public static Object invoke(Object target, String methodName, Object[] args) {\n        try {\n            Class<? extends Object> clazz = target.getClass();\n            Method method = findMethod(clazz, methodName, args);\n            method.setAccessible(true);\n            return method.invoke(target, args);\n        } catch (Exception e) {\n            throw new FlowableException(\"couldn't invoke \" + methodName + \" on \" + target, e);\n        }\n    }\n    \n    public static void invokeSetterOrField(Object target, String name, Object value, boolean throwExceptionOnMissingField) {\n        Method setterMethod = getSetter(name, target.getClass(), value.getClass());\n\n        if (setterMethod != null) {","sourceCodeStart":130,"sourceCodeEnd":166,"githubUrl":"https://github.com/flowable/flowable-engine/blob/d6d39ce1c69ff244f2d9dc6af756a9b95e865586/modules/flowable-engine-common/src/main/java/org/flowable/common/engine/impl/util/ReflectUtil.java#L130-L166","documentation":"ReflectUtil.instantiate creates a new instance of a class by name via its no-arg constructor. Any failure — class not loadable, no default constructor, or constructor throwing — is wrapped in a FlowableException with this message, with the original exception as cause.","triggerScenarios":"Calling ReflectUtil.instantiate(className) where the class is missing, lacks a public no-argument constructor, is abstract/interface, or its constructor throws an exception.","commonSituations":"Custom Flowable classes (delegates, listeners, form types) declared by name in configuration that don't have default constructors; constructor does DI or throws during initialization; class not deployed with the app.","solutions":["Read the cause: ClassNotFoundException → add the class to classpath; NoSuchMethodException/InstantiationException → add a public no-arg constructor.","Ensure the instantiated class is public and concrete (not abstract/interface).","Avoid throwing from the constructor; move initialization to an init method.","If using a DI framework, use delegateExpression with a bean reference instead of class name instantiation.","Verify the class name string in configuration."],"exampleFix":"// before\npublic class MyDelegate {\n    public MyDelegate(String name) { ... } // no default ctor\n}\n// after\npublic class MyDelegate {\n    public MyDelegate() { }\n    public MyDelegate(String name) { ... }\n}","handlingStrategy":"try-catch","validationCode":"Class<?> c = ReflectUtil.loadClass(className);\nif (java.lang.reflect.Modifier.isAbstract(c.getModifiers()) || c.isInterface())\n    throw new IllegalStateException(className + \" is not instantiable\");\ntry { c.getConstructor(); } catch (NoSuchMethodException e) { throw new IllegalStateException(className + \" has no no-arg constructor\"); }","typeGuard":null,"tryCatchPattern":"try {\n    Object o = ReflectUtil.instantiate(className);\n} catch (FlowableException e) {\n    LOGGER.error(\"Instantiate {} failed: {}\", className, e.getCause(), e);\n    throw new IllegalStateException(\"Bad delegate class: \" + className, e.getCause());\n}","preventionTips":["Give all configurable delegate/listener classes public no-arg constructors","Never throw from constructors of reflectively instantiated classes","Prefer delegateExpression (Spring bean) over class-name instantiation","Validate class names in configuration at application startup"],"tags":["reflection","instantiation","java"],"backgroundTag":"class-not-found","analyzedSha":"d6d39ce1c69ff244f2d9dc6af756a9b95e865586","analyzedAt":"2026-09-11T06:41:19.413Z","contentChangedAt":"2026-09-11T06:41:19.413Z","schemaVersion":2},"datasetVersion":"2026-09-18T11:17:12.947Z"}