{"record":{"id":"78e8781352872b90","repo":"apache/cassandra","slug":"failed-to-transfer-field-fieldname","errorCode":null,"errorMessage":"Failed to transfer field: ${fieldName}","messagePattern":"Failed to transfer field: (.+?)","errorType":"exception","errorClass":"RuntimeException","httpStatus":null,"severity":"error","filePath":"src/java/org/apache/cassandra/tools/FieldUtil.java","lineNumber":63,"sourceCode":"        Field modifiers = ReflectionUtils.getModifiersField();\n        modifiers.setAccessible(true);\n        modifiers.setInt(field, field.getModifiers() & ~Modifier.FINAL);\n\n        field.set(null, v);\n    }\n\n    public static void transferFields(Object sourceInstance, Class<?> klass)\n    {\n        for (Field sourceField : sourceInstance.getClass().getDeclaredFields())\n        {\n            sourceField.setAccessible(true);\n            try\n            {\n                setInstanceUnsafe(klass, sourceField.get(sourceInstance), sourceField.getName());\n            }\n            catch (Throwable e)\n            {\n                throw new RuntimeException(\"Failed to transfer field: \" + sourceField.getName(), e);\n            }\n        }\n    }\n}","sourceCodeStart":45,"sourceCodeEnd":67,"githubUrl":"https://github.com/apache/cassandra/blob/88fd0f6a0eaed8943f05ac9e8f947882b8ddc8f1/src/java/org/apache/cassandra/tools/FieldUtil.java#L45-L67","documentation":"FieldUtil.transferFields copies same-named fields from a source instance to a target class via setInstanceUnsafe. Any Throwable raised while setting a field (missing field on target, incompatible types, access failure) is wrapped in this RuntimeException naming the field.","triggerScenarios":"Calling FieldUtil.transferFields(sourceInstance, targetClass) where the target class lacks a field present in the source, the field types are incompatible, or reflection access is blocked, causing setInstanceUnsafe to throw.","commonSituations":"Upgrading a node offline where the old and new schema/state classes differ in fields (version drift); renamed fields between Cassandra versions; serialized state restored into a class whose field set changed.","solutions":["Align the source and target class definitions so every source field has a compatible counterpart on the target.","Check the wrapped cause (e getCause()) to see whether it is NoSuchFieldException, IllegalAccessException, or a type mismatch, and fix accordingly.","Migrate/skip incompatible fields explicitly instead of blanket-transferring all fields.","Ensure the versions of the classes producing and consuming the transferred state match."],"exampleFix":"// before\nFieldUtil.transferFields(oldState, NewState.class); // NewState lacks 'foo'\n// after\n// add field 'foo' to NewState, or remove/ignore it before transfer","handlingStrategy":"try-catch","validationCode":"for (Field f : sourceInstance.getClass().getDeclaredFields()) {\n    try { targetClass.getDeclaredField(f.getName()); }\n    catch (NoSuchFieldException e) { throw new IllegalStateException(\"Target missing field \" + f.getName()); }\n}","typeGuard":null,"tryCatchPattern":"try { FieldUtil.transferFields(source, targetClass); } catch (RuntimeException e) { logger.error(\"Field transfer failed for \" + e.getMessage() + \", cause: \" + e.getCause()); }","preventionTips":["Keep source/target class field sets in sync across versions","Inspect the wrapped cause to identify the exact field problem","Test offline upgrades against both old and new schemas"],"tags":["reflection","field-transfer","type-mismatch","upgrade"],"backgroundTag":"type-mismatch","analyzedSha":"88fd0f6a0eaed8943f05ac9e8f947882b8ddc8f1","analyzedAt":"2026-09-10T07:29:22.284Z","contentChangedAt":"2026-09-10T07:29:22.284Z","schemaVersion":2},"datasetVersion":"2026-09-17T15:17:12.973Z"}