{"record":{"id":"6b2c0faca21c550f","repo":"apache/flink","slug":"fail-to-serialize-at-field-s","errorCode":null,"errorMessage":"Fail to serialize at field: %s.","messagePattern":"Fail to serialize at field: (.+?)\\.","errorType":"exception","errorClass":"RuntimeException","httpStatus":null,"severity":"error","filePath":"flink-formats/flink-avro/src/main/java/org/apache/flink/formats/avro/RowDataToAvroConverters.java","lineNumber":291,"sourceCode":"        final int length = rowType.getFieldCount();\n\n        return new RowDataToAvroConverter() {\n            private static final long serialVersionUID = 1L;\n\n            @Override\n            public Object convert(Schema schema, Object object) {\n                final RowData row = (RowData) object;\n                final List<Schema.Field> fields = schema.getFields();\n                final GenericRecord record = new GenericData.Record(schema);\n                for (int i = 0; i < length; ++i) {\n                    final Schema.Field schemaField = fields.get(i);\n                    try {\n                        Object avroObject =\n                                fieldConverters[i].convert(\n                                        schemaField.schema(), fieldGetters[i].getFieldOrNull(row));\n                        record.put(i, avroObject);\n                    } catch (Throwable t) {\n                        throw new RuntimeException(\n                                String.format(\n                                        \"Fail to serialize at field: %s.\", schemaField.name()),\n                                t);\n                    }\n                }\n                return record;\n            }\n        };\n    }\n\n    private static RowDataToAvroConverter createArrayConverter(\n            ArrayType arrayType, boolean legacyTimestampMapping) {\n        LogicalType elementType = arrayType.getElementType();\n        final ArrayData.ElementGetter elementGetter = ArrayData.createElementGetter(elementType);\n        final RowDataToAvroConverter elementConverter =\n                createConverter(arrayType.getElementType(), legacyTimestampMapping);\n\n        return new RowDataToAvroConverter() {","sourceCodeStart":273,"sourceCodeEnd":309,"githubUrl":"https://github.com/apache/flink/blob/2f3c205e9266cb30240eb7f4fdab15cad629a70f/flink-formats/flink-avro/src/main/java/org/apache/flink/formats/avro/RowDataToAvroConverters.java#L273-L309","documentation":"The row converter wraps per-field conversion so that any failure inside a field's converter is rethrown as RuntimeException('Fail to serialize at field: %s.') naming the offending Avro field. The original error (null in non-nullable field, wrong physical type, nested union problem, decimal overflow) is the cause.","triggerScenarios":"RowData->Avro conversion where field i's value cannot be converted against schemaField.schema(): null for a non-nullable field, decimal precision/scale mismatch, bad union shape (see the not-a-nullable-type error), or unsupported nested type.","commonSituations":"Schema drift between the SQL table and the Avro sink schema; upstream operators introducing nulls; decimal(38,10) values hitting a schema declared with smaller precision.","solutions":["Read the field name from the message and the root cause from getCause(); fix that specific field's nullability, type, or precision.","Make the Avro field nullable ([\"null\",T]) if nulls are expected, or coalesce them away before the sink.","Align declared decimal precision/scale between the table schema and the Avro schema."],"exampleFix":"// error: Fail to serialize at field: amount.\n// cause: null into non-nullable bytes\n\n// before\n{\"name\":\"amount\",\"type\":{\"type\":\"bytes\",\"logicalType\":\"decimal\",\"precision\":10,\"scale\":2}}\n\n// after\n{\"name\":\"amount\",\"type\":[\"null\",{\"type\":\"bytes\",\"logicalType\":\"decimal\",\"precision\":10,\"scale\":2}],\"default\":null}","handlingStrategy":"try-catch","validationCode":"// validate nullability of each value against its field schema before convert\nfor (int i = 0; i < rowType.getFieldCount(); i++) {\n    if (!rowType.getTypeAt(i).isNullable() && row.isNullAt(i)) {\n        throw new IllegalArgumentException(\"Null in non-nullable field: \" + rowType.getFieldNames().get(i));\n    }\n}","typeGuard":null,"tryCatchPattern":"try {\n    record = (GenericRecord) converter.convert(schema, row);\n} catch (RuntimeException e) {\n    // message: 'Fail to serialize at field: %s.' -> identify field, fix data or schema\n    String field = e.getMessage().replace(\"Fail to serialize at field: \", \"\").replace(\".\", \"\");\n    ctx.output(dlqTag, row);\n}","preventionTips":["Make Avro fields nullable wherever the source can emit nulls.","Keep decimal precision/scale consistent between table and Avro schemas.","Use the field name in the message to build targeted data-quality alerts."],"tags":["avro","flink","field-mapping","nullability","debugging"],"backgroundTag":null,"analyzedSha":"2f3c205e9266cb30240eb7f4fdab15cad629a70f","analyzedAt":"2026-08-14T08:48:24.518Z","schemaVersion":2},"datasetVersion":"2026-08-14T10:17:34.591Z"}