{"record":{"id":"bef7bd18689ef400","repo":"flowable/flowable-engine","slug":"could-not-set-field-field-bef7bd","errorCode":null,"errorMessage":"Could not set field ${field}","messagePattern":"Could not set field (.+?)","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":183,"sourceCode":"        } catch (SecurityException e) {\n            throw new ActivitiException(\"not allowed to access field \" + field + \" on class \" + clazz.getCanonicalName(), e);\n        } catch (NoSuchFieldException e) {\n            // for some reason getDeclaredFields doesnt search superclasses\n            // (which getFields() does ... but that gives only public fields)\n            Class<?> superClass = clazz.getSuperclass();\n            if (superClass != null) {\n                return getField(fieldName, superClass);\n            }\n        }\n        return field;\n    }\n\n    public static void setField(Field field, Object object, Object value) {\n        try {\n            field.setAccessible(true);\n            field.set(object, value);\n        } catch (IllegalArgumentException e) {\n            throw new ActivitiException(\"Could not set field \" + field, e);\n        } catch (IllegalAccessException e) {\n            throw new ActivitiException(\"Could not set field \" + field, e);\n        }\n    }\n\n    /**\n     * Returns the setter-method for the given field name or null if no setter exists.\n     */\n    public static Method getSetter(String fieldName, Class<?> clazz, Class<?> fieldType) {\n        String setterName = \"set\" + Character.toTitleCase(fieldName.charAt(0)) +\n                fieldName.substring(1);\n        try {\n            // Using getMethods(), getMethod(...) expects exact parameter type\n            // matching and ignores inheritance-tree.\n            Method[] methods = clazz.getMethods();\n            for (Method method : methods) {\n                if (method.getName().equals(setterName)) {\n                    Class<?>[] paramTypes = method.getParameterTypes();","sourceCodeStart":165,"sourceCodeEnd":201,"githubUrl":"https://github.com/flowable/flowable-engine/blob/d6d39ce1c69ff244f2d9dc6af756a9b95e865586/modules/flowable5-engine/src/main/java/org/activiti/engine/impl/util/ReflectUtil.java#L165-L201","documentation":"ReflectUtil.setField() wraps IllegalArgumentException from Field.set() in an ActivitiException 'Could not set field <field>'. IllegalArgumentException means the value's type is not assignable to the field's declared type (or object is not an instance of the declaring class). The engine throws because reflective writes fail outside the caller's control.","triggerScenarios":"ReflectUtil.setField(field, object, value) is called with a value whose runtime type doesn't match the field's declared type, or with an object that isn't an instance of field.getDeclaringClass().","commonSituations":"Injecting a String into an int field or a subtype mismatch when wiring engine internals/test doubles; refactoring a field's type without updating the reflective write; passing the wrong target object instance.","solutions":["Check the cause IllegalArgumentException for the exact type mismatch","Ensure the value's type matches (or auto-unboxes/boxes to) the field's declared type","Verify you pass the correct object instance of the declaring class","Wrap primitives correctly (Integer for int fields, etc.)"],"exampleFix":"// before\nReflectUtil.setField(field, engineConfiguration, \"5\"); // String into int field\n// after\nReflectUtil.setField(field, engineConfiguration, 5);","handlingStrategy":"type-guard","validationCode":"// check assignability before setting\nif (value != null && !field.getType().isAssignableFrom(value.getClass())) {\n  throw new IllegalArgumentException(\"cannot assign \" + value.getClass() + \" to \" + field.getType());\n}","typeGuard":"boolean settable(Field f, Object value) {\n  return value == null || (f.getType().isAssignableFrom(value.getClass()) || isBoxingMatch(f.getType(), value.getClass()));\n}","tryCatchPattern":"try {\n  ReflectUtil.setField(field, object, value);\n} catch (ActivitiException e) {\n  throw new IllegalStateException(\"type mismatch writing field \" + field.getName(), e);\n}","preventionTips":["Match value types to declared field types (box primitives)","Update reflective writes when refactoring field types","Pass the correct owning object instance","Prefer setters over raw Field.set"],"tags":["reflection","type-mismatch","java"],"backgroundTag":"type-mismatch","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"}