apache/cassandra · error · RuntimeException

Failed to transfer field

Error message

Failed to transfer field: ${fieldName}

What it means

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.

Solutions

  1. Align the source and target class definitions so every source field has a compatible counterpart on the target.
  2. Check the wrapped cause (e getCause()) to see whether it is NoSuchFieldException, IllegalAccessException, or a type mismatch, and fix accordingly.
  3. Migrate/skip incompatible fields explicitly instead of blanket-transferring all fields.
  4. Ensure the versions of the classes producing and consuming the transferred state match.

Example fix

// before
FieldUtil.transferFields(oldState, NewState.class); // NewState lacks 'foo'
// after
// add field 'foo' to NewState, or remove/ignore it before transfer
Defensive patterns

Strategy: try-catch

Validate before calling

for (Field f : sourceInstance.getClass().getDeclaredFields()) {
    try { targetClass.getDeclaredField(f.getName()); }
    catch (NoSuchFieldException e) { throw new IllegalStateException("Target missing field " + f.getName()); }
}

Try / catch

try { FieldUtil.transferFields(source, targetClass); } catch (RuntimeException e) { logger.error("Field transfer failed for " + e.getMessage() + ", cause: " + e.getCause()); }

Prevention

When it happens

Trigger: 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.

Common situations: 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.

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


AI-assisted analysis of apache/cassandra@88fd0f6a0e (2026-09-10). Data as JSON: /api/errors/78e8781352872b90. Report an issue: GitHub.

Appendix: source

Thrown at src/java/org/apache/cassandra/tools/FieldUtil.java:63

        Field modifiers = ReflectionUtils.getModifiersField();
        modifiers.setAccessible(true);
        modifiers.setInt(field, field.getModifiers() & ~Modifier.FINAL);

        field.set(null, v);
    }

    public static void transferFields(Object sourceInstance, Class<?> klass)
    {
        for (Field sourceField : sourceInstance.getClass().getDeclaredFields())
        {
            sourceField.setAccessible(true);
            try
            {
                setInstanceUnsafe(klass, sourceField.get(sourceInstance), sourceField.getName());
            }
            catch (Throwable e)
            {
                throw new RuntimeException("Failed to transfer field: " + sourceField.getName(), e);
            }
        }
    }
}

View on GitHub (pinned to 88fd0f6a0e)