{"record":{"id":"029872c233ba3ba7","repo":"apache/flink","slug":"row-arity-of-reuse-or-from-is-incompatib","errorCode":null,"errorMessage":"Row arity of reuse ({}) or from ({}) is incompatible with this serializer's field length ({}).","messagePattern":"Row arity of reuse \\((.+?)\\) or from \\((.+?)\\) is incompatible with 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":212,"sourceCode":"        if (fieldNames == null) {\n            // reuse uses name-based field mode, do a non-reuse copy\n            if (reuse.getFieldNames(false) != null) {\n                return copy(from);\n            }\n            return copyPositionBased(from, reuse);\n        } else {\n            // reuse uses position-based field mode, do a non-reuse copy\n            if (reuse.getFieldNames(false) == null) {\n                return copy(from);\n            }\n            return copyNameBased(from, fieldNames, reuse);\n        }\n    }\n\n    private Row copyPositionBased(Row from, Row reuse) {\n        final int length = fieldSerializers.length;\n        if (from.getArity() != length || reuse.getArity() != length) {\n            throw new RuntimeException(\n                    \"Row arity of reuse (\"\n                            + reuse.getArity()\n                            + \") or from (\"\n                            + from.getArity()\n                            + \") is \"\n                            + \"incompatible with this serializer's field length (\"\n                            + length\n                            + \").\");\n        }\n        reuse.setKind(from.getKind());\n        for (int i = 0; i < length; i++) {\n            final Object fromField = from.getField(i);\n            if (fromField != null) {\n                final Object reuseField = reuse.getField(i);\n                if (reuseField != null) {\n                    final Object copy = fieldSerializers[i].copy(fromField, reuseField);\n                    reuse.setField(i, copy);\n                } else {","sourceCodeStart":194,"sourceCodeEnd":230,"githubUrl":"https://github.com/apache/flink/blob/2f3c205e9266cb30240eb7f4fdab15cad629a70f/flink-core/src/main/java/org/apache/flink/api/java/typeutils/runtime/RowSerializer.java#L194-L230","documentation":"RowSerializer.copyPositionBased(Row from, Row reuse) is the reuse-optimized copy path for position-based Rows. It checks that BOTH the source Row ('from') and the reuse Row have arity equal to the serializer's field count. If either mismatches, this RuntimeException names both arities and the expected length. Using a reuse Row with the wrong arity is as invalid as a wrong-arity source.","triggerScenarios":"RowSerializer.copy(Row from, Row reuse) is called with either 'from' or 'reuse' having an arity different from fieldSerializers.length. This happens in the reuse-deserialize or reuse-copy code paths that operators use for performance.","commonSituations":"The reuse Row was created with a different arity than the serializer expects (e.g., pre-allocated for a previous schema version); the source Row has evolved to a different arity while the reuse Row was sized for the old one; a generic reuse pool provides Rows of the wrong size; state restore where the reuse buffer was allocated for a different schema.","solutions":["Allocate the reuse Row with exactly fieldSerializers.length fields.","Ensure both source and reuse Rows have the same arity as the serializer.","Do not pool or reuse Row objects across serializers with different arities.","After a schema change, discard old reuse Row buffers and reallocate."],"exampleFix":"// before — reuse Row arity does not match serializer\nRowSerializer ser = new RowSerializer(new TypeSerializer[]{intSer, strSer}); // length 2\nRow reuse = new Row(3); // wrong arity\nser.copy(Row.of(1, \"a\"), reuse); // reuse arity 3 ≠ 2 → exception\n\n// after — reuse Row matches serializer arity\nRow reuse = new Row(2); // matches fieldSerializers.length\nser.copy(Row.of(1, \"a\"), reuse); // OK","handlingStrategy":"validation","validationCode":"// Validate both source and reuse arity before reuse-copy\npublic static Row safeCopy(RowSerializer ser, Row from, Row reuse) {\n    int expected = ser.getArity();\n    if (from.getArity() != expected || reuse.getArity() != expected) {\n        throw new IllegalArgumentException(\n            \"Arity mismatch: from=\" + from.getArity()\n            + \", reuse=\" + reuse.getArity() + \", expected=\" + expected);\n    }\n    return ser.copy(from, reuse);\n}","typeGuard":null,"tryCatchPattern":"try {\n    Row result = serializer.copy(from, reuse);\n} catch (RuntimeException e) {\n    if (e.getMessage().contains(\"incompatible with this serializer's field length\")) {\n        log.error(\"Reuse or source arity wrong: from={}, reuse={}, expected={}\",\n            from.getArity(), reuse.getArity(), serializer.getArity());\n        reuse = serializer.createInstance(); // fix reuse\n    }\n    throw e;\n}","preventionTips":["Allocate reuse Rows via serializer.createInstance() to guarantee correct arity.","Never pool Rows across serializers with different arities.","Reallocate reuse buffers after schema changes.","Validate arity before reuse-copy operations."],"tags":["row","serializer","arity-mismatch","reuse","schema"],"backgroundTag":null,"analyzedSha":"2f3c205e9266cb30240eb7f4fdab15cad629a70f","analyzedAt":"2026-08-14T08:48:24.518Z","schemaVersion":2},"datasetVersion":"2026-08-14T10:17:34.591Z"}