flowable/flowable-engine · error · ActivitiException
Error while invoking '%s' on class %s
Error message
Error while invoking '%s' on class %s
What it means
When applying a field declaration (activiti:field extension) to the delegate instance, ClassDelegate first tries setter injection via reflection. If the setter exists but Method.invoke throws IllegalArgumentException (e.g. the declared value's type cannot be converted to the setter's parameter type), this ActivitiException wraps the cause.
Source
Thrown at modules/flowable5-engine/src/main/java/org/activiti/engine/impl/bpmn/helper/ClassDelegate.java:271
for (FieldDeclaration declaration : fieldDeclarations) {
applyFieldDeclaration(declaration, target, throwExceptionOnMissingField);
}
}
}
public static void applyFieldDeclaration(FieldDeclaration declaration, Object target) {
applyFieldDeclaration(declaration, target, true);
}
public static void applyFieldDeclaration(FieldDeclaration declaration, Object target, boolean throwExceptionOnMissingField) {
Method setterMethod = ReflectUtil.getSetter(declaration.getName(),
target.getClass(), declaration.getValue().getClass());
if (setterMethod != null) {
try {
setterMethod.invoke(target, declaration.getValue());
} catch (IllegalArgumentException e) {
throw new ActivitiException("Error while invoking '" + declaration.getName() + "' on class " + target.getClass().getName(), e);
} catch (IllegalAccessException e) {
throw new ActivitiException("Illegal access when calling '" + declaration.getName() + "' on class " + target.getClass().getName(), e);
} catch (InvocationTargetException e) {
throw new ActivitiException("Exception while invoking '" + declaration.getName() + "' on class " + target.getClass().getName(), e);
}
} else {
Field field = ReflectUtil.getField(declaration.getName(), target);
if (field == null) {
if (throwExceptionOnMissingField) {
throw new ActivitiIllegalArgumentException("Field definition uses unexisting field '" + declaration.getName() + "' on class " + target.getClass().getName());
} else {
return;
}
}
// Check if the delegate field's type is correct
if (!fieldTypeCompatible(declaration, field)) {
throw new ActivitiIllegalArgumentException("Incompatible type set on field declaration '" + declaration.getName()View on GitHub (pinned to d6d39ce1c6)
Solutions
- Align the field declaration type with the setter parameter type (use stringValue, expression, or the correct FixedValue type in the BPMN XML).
- Change the delegate setter to accept the declared type (e.g. accept Expression or String and convert inside).
- Inspect the wrapped IllegalArgumentException cause to identify the exact parameter mismatch.
Example fix
// before (BPMN)
<activiti:field name="count"><activiti:string>abc</activiti:string></activiti:field>
// setter: public void setCount(int count)
// after
<activiti:field name="count"><activiti:string>42</activiti:string></activiti:field>
// setter: public void setCount(String count) { this.count = Integer.parseInt(count); } Defensive patterns
Strategy: validation
Validate before calling
Method m = delegate.getClass().getMethod("set" + capitalize(fieldName), value.getClass());
// resolve setter before wiring the field declaration; fail fast on mismatch Type guard
boolean setterAccepts(Object target, String field, Object value) {
try { target.getClass().getMethod("set" + Character.toUpperCase(field.charAt(0)) + field.substring(1), value.getClass()); return true; }
catch (NoSuchMethodException e) { return false; }
} Try / catch
try {
runtimeService.startProcessInstanceByKey(key, vars);
} catch (ActivitiException e) {
if (e.getMessage().startsWith("Error while invoking")) {
log.error("Field injection type mismatch; check activiti:field value vs setter", e);
} else throw e;
} Prevention
- Keep activiti:field value element type (string/expression) aligned with setter signatures
- Add deployment-time validation tests that instantiate delegates with their field declarations
- Prefer Expression-typed setters to accept both literals and EL
When it happens
Trigger: A field declaration whose value type does not match the delegate's setter parameter (e.g. string value passed to setCount(int) without matching expression type), causing setterMethod.invoke(target, value) to fail with IllegalArgumentException.
Common situations: BPMN XML activiti:field with stringValue/string vs an Expression/Date/int setter; delegate refactored to change setter signature while process XML still declares old type; Spring bean field injection with incompatible EL result.
Understand the failure class
Background: Type mismatch errors: IllegalArgumentException, TypeError and type guards across 150 open-source libraries — this error's family across 150 libraries.
Related errors
- Error while invoking '%s' on class %s
- Incompatible type set on field declaration '${name}' for cla
- Could not set field ${field}
- Error while invoking '<fieldName>' on class <className>
- Illegal access when calling '%s' on class %s
AI-assisted analysis of flowable/flowable-engine@d6d39ce1c6 (2026-09-11).
Data as JSON: /api/errors/2233f1d46a1c0bae.
Report an issue: GitHub.