{"record":{"id":"f828e6200a652672","repo":"flowable/flowable-engine","slug":"couldn-t-instantiate-class-classname-f828e6","errorCode":null,"errorMessage":"couldn't instantiate class ${className}","messagePattern":"couldn't instantiate class (.+?)","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":136,"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.newInstance();\n        } catch (Exception e) {\n            throw new ActivitiException(\"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 ActivitiException(\"couldn't invoke \" + methodName + \" on \" + target, e);\n        }\n    }\n\n    /**\n     * Returns the field of the given object or null if it doesnt exist.\n     */\n    public static Field getField(String fieldName, Object object) {","sourceCodeStart":118,"sourceCodeEnd":154,"githubUrl":"https://github.com/flowable/flowable-engine/blob/d6d39ce1c69ff244f2d9dc6af756a9b95e865586/modules/flowable5-engine/src/main/java/org/activiti/engine/impl/util/ReflectUtil.java#L118-L154","documentation":"ReflectUtil.instantiate loads a class by name and creates a new instance via newInstance(). Any failure in loading or construction (ClassNotFoundException, no public no-arg constructor, constructor throwing, abstract/interface target) is wrapped in this ActivitiException.","triggerScenarios":"Calling ReflectUtil.instantiate(className) where the class is absent from the classpath, is an interface/abstract class, lacks a public no-argument constructor, or its constructor throws an exception.","commonSituations":"Configuring custom delegate classes or handlers with class names that were renamed or moved packages; dependencies of the class missing from the runtime classpath; updating a delegate class without updating process configuration.","solutions":["Verify the class name (fully qualified, correct case) and that its jar is on the runtime classpath.","Ensure the class is concrete and has a public no-argument constructor.","Check the wrapped cause: ClassNotFoundException vs InvocationTargetException vs InstantiationException identifies which case applies.","Run the constructor manually to surface any exception thrown during instantiation."],"exampleFix":"// before (config)\n<field name=\"customProvider\" value=\"com.acme.OldProvider\"/>  <!-- class removed -->\n// after: update to the current FQCN and provide a public no-arg constructor\n<field name=\"customProvider\" value=\"com.acme.NewProvider\"/>\npublic class NewProvider { public NewProvider() {} }","handlingStrategy":"try-catch","validationCode":"Class<?> c;\ntry { c = Class.forName(className); } catch (ClassNotFoundException e) { throw new IllegalStateException(\"Not on classpath: \" + className); }\nint mods = c.getModifiers();\nif (Modifier.isAbstract(mods) || c.isInterface() || !Modifier.isPublic(mods)) throw new IllegalStateException(\"Not instantiable: \" + className);\ntry { c.getConstructor(); } catch (NoSuchMethodException e) { throw new IllegalStateException(\"No public no-arg constructor: \" + className); }","typeGuard":null,"tryCatchPattern":"try {\n    Object o = ReflectUtil.instantiate(className);\n} catch (ActivitiException e) {\n    if (e.getCause() instanceof ClassNotFoundException) { /* fix classpath/name */ }\n    else if (e.getCause() instanceof InstantiationException) { /* abstract or interface */ }\n    else if (e.getCause() instanceof InvocationTargetException) { /* constructor threw */ }\n}","preventionTips":["Keep configured class names in sync when refactoring packages (search configs for old FQCNs)","Require a public no-arg constructor on all delegate/configurable classes","Add a startup smoke test that instantiates all configured custom classes"],"tags":["reflection","classloading","instantiation"],"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"}