{"record":{"id":"09867ec67b3eb5a6","repo":"flowable/flowable-engine","slug":"exception-while-invoking-s-on-class-s-09867e","errorCode":null,"errorMessage":"Exception while invoking '%s' on class %s","messagePattern":"Exception while invoking '(.+?)' on class (.+?)","errorType":"exception","errorClass":"ActivitiException","httpStatus":null,"severity":"error","filePath":"modules/flowable5-engine/src/main/java/org/activiti/engine/impl/bpmn/helper/ClassDelegateUtil.java","lineNumber":60,"sourceCode":"            for (FieldDeclaration declaration : fieldDeclarations) {\n                applyFieldDeclaration(declaration, target);\n            }\n        }\n    }\n\n    public static void applyFieldDeclaration(FieldDeclaration declaration, Object target) {\n        Method setterMethod = ReflectUtil.getSetter(declaration.getName(),\n                target.getClass(), declaration.getValue().getClass());\n\n        if (setterMethod != null) {\n            try {\n                setterMethod.invoke(target, declaration.getValue());\n            } catch (IllegalArgumentException e) {\n                throw new ActivitiException(\"Error while invoking '\" + declaration.getName() + \"' on class \" + target.getClass().getName(), e);\n            } catch (IllegalAccessException e) {\n                throw new ActivitiException(\"Illegal access when calling '\" + declaration.getName() + \"' on class \" + target.getClass().getName(), e);\n            } catch (InvocationTargetException e) {\n                throw new ActivitiException(\"Exception while invoking '\" + declaration.getName() + \"' on class \" + target.getClass().getName(), e);\n            }\n        } else {\n            Field field = ReflectUtil.getField(declaration.getName(), target);\n            if (field == null) {\n                throw new ActivitiIllegalArgumentException(\"Field definition uses unexisting field '\" + declaration.getName() + \"' on class \" + target.getClass().getName());\n            }\n            // Check if the delegate field's type is correct\n            if (!fieldTypeCompatible(declaration, field)) {\n                throw new ActivitiIllegalArgumentException(\"Incompatible type set on field declaration '\" + declaration.getName()\n                        + \"' for class \" + target.getClass().getName()\n                        + \". Declared value has type \" + declaration.getValue().getClass().getName()\n                        + \", while expecting \" + field.getType().getName());\n            }\n            ReflectUtil.setField(field, target, declaration.getValue());\n        }\n    }\n\n    public static boolean fieldTypeCompatible(FieldDeclaration declaration, Field field) {","sourceCodeStart":42,"sourceCodeEnd":78,"githubUrl":"https://github.com/flowable/flowable-engine/blob/d6d39ce1c69ff244f2d9dc6af756a9b95e865586/modules/flowable5-engine/src/main/java/org/activiti/engine/impl/bpmn/helper/ClassDelegateUtil.java#L42-L78","documentation":"Thrown when the setter invoked via reflection to apply a BPMN field injection raised an InvocationTargetException, i.e. the delegate's own setter method threw an exception internally. The engine rewraps it as an ActivitiException naming the field and target class.","triggerScenarios":"The setter method for an injected flowable:field executes and throws any runtime exception (e.g. parsing an invalid literal, NPE on an assumed dependency) during ClassDelegateUtil.applyFieldDeclaration.","commonSituations":"Setters that validate/transform the injected value and throw on bad input; setters that depend on state not yet initialized at delegate instantiation; type conversion mistakes inside the setter.","solutions":["Inspect the cause stack trace: the real error is inside your delegate's setter","Fix the exception thrown inside the setter (e.g. handle the injected value safely)","Add null/format validation inside the setter before processing the value","If the setter must not fail at injection time, defer the logic to the execute() method"],"exampleFix":"// before\npublic void setTimeout(String timeout) {\n    this.timeout = Integer.parseInt(timeout); // throws on non-numeric\n}\n// after\npublic void setTimeout(String timeout) {\n    this.timeout = timeout != null ? Integer.parseInt(timeout) : 0;\n}","handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"try {\n    applyFieldDeclaration(declaration, target);\n} catch (org.activiti.engine.ActivitiException e) {\n    logger.error(\"Field injection failed on {}\", declaration.getName(), e.getCause());\n    throw e;\n}","preventionTips":["Never throw from delegate setters during injection; validate lazily in execute()","Unit test delegates with their BPMN field declarations","Log and inspect the cause chain — the root exception is inside your setter"],"tags":["java","reflection","bpmn","field-injection"],"backgroundTag":"invalid-argument-value","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"}