{"record":{"id":"50ac3c254527d9fa","repo":"apache/iceberg","slug":"fail-to-serialize-at-field-s-50ac3c","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/v2.2/flink/src/main/java/org/apache/iceberg/flink/formats/avro/RowDataToAvroConverters.java","lineNumber":333,"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(\"Fail to serialize at field: %s.\", schemaField.name()), 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() {\n      private static final long serialVersionUID = 1L;\n","sourceCodeStart":315,"sourceCodeEnd":351,"githubUrl":"https://github.com/apache/iceberg/blob/86d9c8fc543e7c56c9f624eb725f76c9baff9570/flink/v2.2/flink/src/main/java/org/apache/iceberg/flink/formats/avro/RowDataToAvroConverters.java#L315-L351","documentation":"The record-level convert() in RowDataToAvroConverters serializes each field via its converter and getter. If any field conversion throws (type mismatch, null in a non-nullable Avro field, converter failure), it is wrapped in a RuntimeException naming the offending field via 'Fail to serialize at field: <name>.' with the original exception as cause.","triggerScenarios":"Calling convert() on a RowData whose field value does not match the Avro schema at that position: null for a non-nullable field, wrong type for the declared branch, or an unsupported nested value.","commonSituations":"Writing Flink rows to Iceberg/Avro files where a column holds null but the Avro schema marks it non-null; schema and RowData drifted after a table schema change; decimal/timestamp precision mismatches.","solutions":["Inspect the cause exception to find the real failure, then fix the data or schema at that field.","Make the Avro schema field nullable ([\"null\", T]) if nulls are legitimate in the data.","Re-derive the Avro schema from the current Flink type so schema and RowData match (AvroSchemaConverter.convertToSchema).","Sanitize/coerce values before writing: convert types (e.g. timestamp precision) and replace nulls with defaults for required fields."],"exampleFix":"// before\nschema field \"ts\": {\"type\":\"long\",\"logicalType\":\"timestamp-millis\"}, data has micros TimestampData\n// after\nregenerate schema with local-timestamp-micros or truncate the value to millis before writing","handlingStrategy":"try-catch","validationCode":"for (int i = 0; i < row.getArity(); i++) {\n  if (schemaField(i).schema.getType() != Schema.Type.UNION && row.getField(i) == null) {\n    throw new IllegalArgumentException(\"null value for non-nullable Avro field: \" + schemaField(i).name());\n  }\n}","typeGuard":null,"tryCatchPattern":"try { record = converter.convert(schema, row); } catch (RuntimeException e) { log.error(\"{} cause={}\", e.getMessage(), e.getCause(), e); throw e; }","preventionTips":["Always inspect e.getCause() — the wrapper hides the real field-level failure.","Keep Avro schema and RowData type derived from the same source of truth.","Re-derive schemas after any table schema evolution.","Declare nullable Avro fields ([\"null\", T]) wherever nulls are possible in data."],"tags":["flink","avro","serialization","field-mismatch"],"backgroundTag":"json-serialization-failed","analyzedSha":"86d9c8fc543e7c56c9f624eb725f76c9baff9570","analyzedAt":"2026-09-12T00:46:39.097Z","contentChangedAt":"2026-09-12T00:46:39.097Z","schemaVersion":2},"datasetVersion":"2026-09-14T16:17:12.679Z"}