apache/flink · error · RuntimeException

Row arity of record ({}) does not match this serializer's fi

Error message

Row arity of record ({}) does not match this serializer's field length ({}).

What it means

RowSerializer.serializePositionBased() writes a position-based Row to a DataOutputView. Before serializing, it asserts record.getArity() == fieldSerializers.length. If the Row has more or fewer fields than the serializer expects, this RuntimeException is thrown with both values. Serialization requires an exact arity match because the binary format uses a fixed-length null bitmask sized to the serializer's field count.

Source

Thrown at flink-core/src/main/java/org/apache/flink/api/java/typeutils/runtime/RowSerializer.java:286

    public int getArity() {
        return arity;
    }

    @Override
    public void serialize(Row record, DataOutputView target) throws IOException {
        final Set<String> fieldNames = record.getFieldNames(false);
        if (fieldNames == null) {
            serializePositionBased(record, target);
        } else {
            serializeNameBased(record, fieldNames, target);
        }
    }

    private void serializePositionBased(Row record, DataOutputView target) throws IOException {
        final int length = fieldSerializers.length;
        if (record.getArity() != length) {
            throw new RuntimeException(
                    "Row arity of record ("
                            + record.getArity()
                            + ") does not match this "
                            + "serializer's field length ("
                            + length
                            + ").");
        }

        // write bitmask
        fillMask(length, record, mask, supportsRowKind, rowKindOffset);
        writeMask(mask, target);

        // serialize non-null fields
        for (int fieldPos = 0; fieldPos < length; fieldPos++) {
            final Object o = record.getField(fieldPos);
            if (o != null) {
                fieldSerializers[fieldPos].serialize(o, target);
            }

View on GitHub (pinned to 2f3c205e92)

Solutions

  1. Ensure every Row serialized has arity == fieldSerializers.length.
  2. Align the TypeInformation/RowSerializer arity with the upstream operator's output schema.
  3. Validate arity in a MapFunction before the data reaches the serializer/network layer.
  4. After schema changes, reset state or implement migration.

Example fix

// before — Row arity 3, serializer expects 2
RowSerializer ser = new RowSerializer(new TypeSerializer[]{intSer, strSer});
ser.serialize(Row.of(1, "a", 42), output); // arity 3 ≠ 2 → exception

// after — serializer arity matches data
RowSerializer ser = new RowSerializer(new TypeSerializer[]{intSer, strSer, intSer});
ser.serialize(Row.of(1, "a", 42), output); // OK
Defensive patterns

Strategy: validation

Validate before calling

// Validate Row arity before serialization
public static void safeSerialize(RowSerializer ser, Row record, DataOutputView out)
        throws IOException {
    if (record.getArity() != ser.getArity()) {
        throw new IllegalArgumentException(
            "Row arity " + record.getArity()
            + " != serializer arity " + ser.getArity());
    }
    ser.serialize(record, out);
}

Try / catch

try {
    serializer.serialize(record, output);
} catch (RuntimeException e) {
    if (e.getMessage().contains("Row arity of record")) {
        log.error("Cannot serialize: Row arity {} != expected {}",
            record.getArity(), serializer.getArity());
    }
    throw e;
}

Prevention

When it happens

Trigger: RowSerializer.serialize(Row, DataOutputView) is called during network shuffle, checkpointing, or state backend write, and the Row's arity differs from the serializer's configured field count.

Common situations: An upstream operator changed the Row schema (added/removed a column) but the downstream serializer was not updated; two streams with different Row arities were unioned and fed into one operator; state restore from a savepoint with an older Row schema; a source connector emits Rows with the wrong number of fields.

Related errors


AI-assisted analysis of apache/flink@2f3c205e92 (2026-08-14). Data as JSON: /api/errors/a43509fd87489d30. Report an issue: GitHub.