{"record":{"id":"74bbce39228d7df6","repo":"apache/flink","slug":"field-at-index-s-must-be-of-type-byte-but-was","errorCode":null,"errorMessage":"Field at index %s must be of type byte[], but was %s","messagePattern":"Field at index (.+?) must be of type byte\\[\\], but was (.+?)","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"flink-core/src/main/java/org/apache/flink/api/common/serialization/RowFieldExtractorSchema.java","lineNumber":97,"sourceCode":"    @Override\n    public byte[] serialize(@Nullable Row element) {\n        if (element == null) {\n            return new byte[0];\n        }\n\n        checkArgument(\n                fieldIndex < element.getArity(),\n                \"Cannot access field %s in Row with arity %s\",\n                fieldIndex,\n                element.getArity());\n\n        Object field = element.getField(fieldIndex);\n        if (field == null) {\n            return new byte[0];\n        }\n\n        if (!(field instanceof byte[])) {\n            throw new IllegalArgumentException(\n                    String.format(\n                            \"Field at index %s must be of type byte[], but was %s\",\n                            fieldIndex, field.getClass().getName()));\n        }\n\n        return (byte[]) field;\n    }\n\n    @Override\n    public boolean equals(Object o) {\n        if (this == o) {\n            return true;\n        }\n        if (o == null || getClass() != o.getClass()) {\n            return false;\n        }\n        RowFieldExtractorSchema that = (RowFieldExtractorSchema) o;\n        return fieldIndex == that.fieldIndex;","sourceCodeStart":79,"sourceCodeEnd":115,"githubUrl":"https://github.com/apache/flink/blob/2f3c205e9266cb30240eb7f4fdab15cad629a70f/flink-core/src/main/java/org/apache/flink/api/common/serialization/RowFieldExtractorSchema.java#L79-L115","documentation":"Thrown by RowFieldExtractorSchema.serialize when the Row field at the configured index exists but is not a byte[]. This schema is designed solely to extract a raw byte[] field (e.g. a pre-serialized Kafka key or value), so any other type is a programming error. The message reports the actual field type so the developer can correct the Row schema or the extractor index.","triggerScenarios":"Calling serialize() on a Row where the field at fieldIndex is a String, Integer, or any non-byte[] type. This happens when the upstream Row schema was defined with a non-VARBINARY/BINARY field but the RowFieldExtractorSchema was configured to read that index.","commonSituations":"Mismatch between the Table/Row schema field types and the configured KafkaRecordSerializationSchema key/value extractor; changing a field type from BYTES to STRING without updating the extractor; indexing the wrong field that happens to be a non-binary column.","solutions":["Ensure the Row field at the configured index is actually byte[] (BINARY/VARBINARY in the Table schema).","If the field is a String or other type, convert it to byte[] before it enters the Row, or use a different SerializationSchema (e.g. a JSON or string schema).","Verify the fieldIndex argument matches the intended binary column; reorder the Row or change the index."],"exampleFix":"// before: Row has a String at index 1\nRow.of(123L, \"hello\");\nnew RowFieldExtractorSchema(1); // throws: field is String not byte[]\n\n// after: store bytes at index 1\nRow.of(123L, \"hello\".getBytes(StandardCharsets.UTF_8));\nnew RowFieldExtractorSchema(1);","handlingStrategy":"validation","validationCode":"// Validate the Row field type before serializing\nObject field = row.getField(index);\nif (field != null && !(field instanceof byte[])) {\n    throw new IllegalStateException(\n        \"Row field at index \" + index + \" is \" + field.getClass().getName()\n        + \" — convert to byte[] before using RowFieldExtractorSchema.\");\n}","typeGuard":"public static boolean isByteField(Row row, int index) {\n    Object field = row.getField(index);\n    return field == null || field instanceof byte[];\n}","tryCatchPattern":"try {\n    byte[] out = extractor.serialize(row);\n} catch (IllegalArgumentException e) {\n    if (e.getMessage().startsWith(\"Field at index\")) {\n        // route to error handling / side output\n    } else {\n        throw e;\n    }\n}","preventionTips":["Define the Row schema so the extracted field is BINARY/VARBINARY.","Validate field types against the extractor index in a unit test.","Convert String/other types to byte[] before building the Row."],"tags":["serialization","row","type-mismatch","kafka"],"backgroundTag":null,"analyzedSha":"2f3c205e9266cb30240eb7f4fdab15cad629a70f","analyzedAt":"2026-08-14T08:48:24.518Z","schemaVersion":2},"datasetVersion":"2026-08-14T10:17:34.591Z"}