{"record":{"id":"a43509fd87489d30","repo":"apache/flink","slug":"row-arity-of-record-does-not-match-this-seria","errorCode":null,"errorMessage":"Row arity of record ({}) does not match this serializer's field length ({}).","messagePattern":"Row arity of record \\((.+?)\\) does not match this serializer's field length \\((.+?)\\)\\.","errorType":"exception","errorClass":"RuntimeException","httpStatus":null,"severity":"error","filePath":"flink-core/src/main/java/org/apache/flink/api/java/typeutils/runtime/RowSerializer.java","lineNumber":286,"sourceCode":"\n    public int getArity() {\n        return arity;\n    }\n\n    @Override\n    public void serialize(Row record, DataOutputView target) throws IOException {\n        final Set<String> fieldNames = record.getFieldNames(false);\n        if (fieldNames == null) {\n            serializePositionBased(record, target);\n        } else {\n            serializeNameBased(record, fieldNames, target);\n        }\n    }\n\n    private void serializePositionBased(Row record, DataOutputView target) throws IOException {\n        final int length = fieldSerializers.length;\n        if (record.getArity() != length) {\n            throw new RuntimeException(\n                    \"Row arity of record (\"\n                            + record.getArity()\n                            + \") does not match this \"\n                            + \"serializer's field length (\"\n                            + length\n                            + \").\");\n        }\n\n        // write bitmask\n        fillMask(length, record, mask, supportsRowKind, rowKindOffset);\n        writeMask(mask, target);\n\n        // serialize non-null fields\n        for (int fieldPos = 0; fieldPos < length; fieldPos++) {\n            final Object o = record.getField(fieldPos);\n            if (o != null) {\n                fieldSerializers[fieldPos].serialize(o, target);\n            }","sourceCodeStart":268,"sourceCodeEnd":304,"githubUrl":"https://github.com/apache/flink/blob/2f3c205e9266cb30240eb7f4fdab15cad629a70f/flink-core/src/main/java/org/apache/flink/api/java/typeutils/runtime/RowSerializer.java#L268-L304","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Ensure every Row serialized has arity == fieldSerializers.length.","Align the TypeInformation/RowSerializer arity with the upstream operator's output schema.","Validate arity in a MapFunction before the data reaches the serializer/network layer.","After schema changes, reset state or implement migration."],"exampleFix":"// before — Row arity 3, serializer expects 2\nRowSerializer ser = new RowSerializer(new TypeSerializer[]{intSer, strSer});\nser.serialize(Row.of(1, \"a\", 42), output); // arity 3 ≠ 2 → exception\n\n// after — serializer arity matches data\nRowSerializer ser = new RowSerializer(new TypeSerializer[]{intSer, strSer, intSer});\nser.serialize(Row.of(1, \"a\", 42), output); // OK","handlingStrategy":"validation","validationCode":"// Validate Row arity before serialization\npublic static void safeSerialize(RowSerializer ser, Row record, DataOutputView out)\n        throws IOException {\n    if (record.getArity() != ser.getArity()) {\n        throw new IllegalArgumentException(\n            \"Row arity \" + record.getArity()\n            + \" != serializer arity \" + ser.getArity());\n    }\n    ser.serialize(record, out);\n}","typeGuard":null,"tryCatchPattern":"try {\n    serializer.serialize(record, output);\n} catch (RuntimeException e) {\n    if (e.getMessage().contains(\"Row arity of record\")) {\n        log.error(\"Cannot serialize: Row arity {} != expected {}\",\n            record.getArity(), serializer.getArity());\n    }\n    throw e;\n}","preventionTips":["Validate Row.getArity() == serializer.getArity() before every serialize call.","Keep Row schema and serializer schema in sync — update both together.","Add arity validation at source connectors.","Reset state after schema changes."],"tags":["row","serializer","arity-mismatch","serialization","schema"],"backgroundTag":null,"analyzedSha":"2f3c205e9266cb30240eb7f4fdab15cad629a70f","analyzedAt":"2026-08-14T08:48:24.518Z","schemaVersion":2},"datasetVersion":"2026-08-14T10:17:34.591Z"}