{"record":{"id":"7e3c450c11ec3e2e","repo":"apache/iceberg","slug":"fail-to-serialize-at-field-s-7e3c45","errorCode":null,"errorMessage":"Fail to serialize at field: %s.","messagePattern":"Fail to serialize at field: (.+?)\\.","errorType":"exception","errorClass":"java.lang.RuntimeException","httpStatus":null,"severity":"error","filePath":"flink/v2.1/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.1/flink/src/main/java/org/apache/iceberg/flink/formats/avro/RowDataToAvroConverters.java#L315-L351","documentation":"Wrapping error from RowDataToAvroConverters' record converter: an exception escaped while converting one field of a RowData to its Avro representation, and it is rethrown with the offending field name (%s) added for diagnosis. The root cause (class cast, null, or numeric problem) is chained — inspect the cause for the real failure.","triggerScenarios":"Any per-field converter failure during record serialization: type mismatches, null handling errors, converter bugs, or schema/data divergence for a specific field.","commonSituations":"A single corrupt or wrong-typed field in an otherwise valid row breaks the whole record serialization when writing Avro files; debugging which column caused a serialization batch failure.","solutions":["Read the wrapped cause ('Caused by') to find the real converter failure and fix the underlying data or schema","Validate row data types against the table schema before writing","Regenerate the Avro schema from the current table schema so field types align","Add null checks / casts in the pipeline for nullable or heterogeneous fields"],"exampleFix":"// cause: field \"ts\" holds String but schema expects long\n// before\nrow.setField(2, \"2024-01-01\");\n// after\nrow.setField(2, TimestampData.fromLocalDateTime(LocalDateTime.parse(\"2024-01-01T00:00:00\")));","handlingStrategy":"try-catch","validationCode":"for (int i = 0; i < row.getArity(); i++) {\n  Object v = row.getField(i);\n  if (v != null && !typeMatches(rowType.getTypeAt(i), v.getClass())) {\n    throw new IllegalStateException(\"Field \" + schema.getField(i).name() + \" type mismatch: \" + v.getClass());\n  }\n}","typeGuard":null,"tryCatchPattern":"try {\n  Object avro = recordConverter.convert(schema, row);\n} catch (RuntimeException e) {\n  if (e.getMessage() != null && e.getMessage().startsWith(\"Fail to serialize at field:\")) {\n    LOG.error(\"Bad field {}. Cause: {}\", e.getMessage(), e.getCause());\n    // inspect e.getCause() for the underlying converter failure\n  } else { throw e; }\n}","preventionTips":["Always inspect the 'Caused by' chain — this message only names the field","Validate row values against the table schema before writing","Keep the Avro schema in sync with the table schema","Unit-test serialization for all row field types including nulls"],"tags":["flink","avro","serialization"],"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"}