{"record":{"id":"95052117b9cce3fd","repo":"apache/iceberg","slug":"unknown-type-for-binary-field-type-name-byte","errorCode":null,"errorMessage":"Unknown type for binary field. Type name: \" + bytes.getClass().getName()","messagePattern":"Unknown type for binary field\\. Type name: \" \\+ bytes\\.getClass\\(\\)\\.getName\\(\\)","errorType":"exception","errorClass":"IllegalStateException","httpStatus":null,"severity":"error","filePath":"flink/v2.2/flink/src/main/java/org/apache/iceberg/flink/data/StructRowData.java","lineNumber":238,"sourceCode":"    return isNullAt(pos) ? null : getBinaryInternal(pos);\n  }\n\n  private byte[] getBinaryInternal(int pos) {\n    Object bytes = struct.get(pos, Object.class);\n\n    // should only be either ByteBuffer or byte[]\n    if (bytes instanceof ByteBuffer) {\n      return ByteBuffers.toByteArray((ByteBuffer) bytes);\n    } else if (bytes instanceof byte[]) {\n      return (byte[]) bytes;\n    } else if (bytes instanceof UUID) {\n      UUID uuid = (UUID) bytes;\n      ByteBuffer bb = ByteBuffer.allocate(16);\n      bb.putLong(uuid.getMostSignificantBits());\n      bb.putLong(uuid.getLeastSignificantBits());\n      return bb.array();\n    } else {\n      throw new IllegalStateException(\n          \"Unknown type for binary field. Type name: \" + bytes.getClass().getName());\n    }\n  }\n\n  @Override\n  public ArrayData getArray(int pos) {\n    return isNullAt(pos)\n        ? null\n        : (ArrayData)\n            convertValue(type.fields().get(pos).type().asListType(), struct.get(pos, List.class));\n  }\n\n  @Override\n  public MapData getMap(int pos) {\n    return isNullAt(pos)\n        ? null\n        : (MapData)\n            convertValue(type.fields().get(pos).type().asMapType(), struct.get(pos, Map.class));","sourceCodeStart":220,"sourceCodeEnd":256,"githubUrl":"https://github.com/apache/iceberg/blob/86d9c8fc543e7c56c9f624eb725f76c9baff9570/flink/v2.2/flink/src/main/java/org/apache/iceberg/flink/data/StructRowData.java#L220-L256","documentation":"StructRowData.getBinaryInternal converts the value stored in the wrapped StructLike into a Flink binary (byte[]). Only ByteBuffer, byte[], and UUID (Iceberg's fixed-length UUID representation) are supported; any other stored runtime type causes IllegalStateException with the class name, indicating the field's value doesn't match a binary/fixed/uuid column.","triggerScenarios":"Calling getBinary(pos) on StructRowData when the StructLike holds e.g. String, CharSequence, or a custom type rather than ByteBuffer/byte[]/UUID for a binary, fixed, or uuid column.","commonSituations":"Custom writer storing binary as base64 String; StructLike adapters (e.g. wrapping external records) mapping fixed/uuid fields to non-standard classes; schema mismatch where a string column is read through a binary-typed schema.","solutions":["Look at the class in the message and normalize the stored value to ByteBuffer, byte[], or UUID upstream.","If values are stored as Strings, decode them (base64 or UTF-8) before wrapping the row.","Verify the read schema matches the physical column types so binary columns aren't served strings.","Fix the custom StructLike implementation to return ByteBuffer for FIXED/BINARY fields, as StructRowData's convertValue path also assumes ByteBuffer."],"exampleFix":"// before\nbyte[] b = structRowData.getBinary(pos); // fails for String-stored values\n\n// after\nObject raw = struct.get(pos, Object.class);\nbyte[] b = (raw instanceof String s)\n    ? java.util.Base64.getDecoder().decode(s)\n    : structRowData.getBinary(pos);","handlingStrategy":"validation","validationCode":"Object raw = struct.get(pos, Object.class);\nPreconditions.checkArgument(\n    raw == null || raw instanceof ByteBuffer || raw instanceof byte[] || raw instanceof UUID,\n    \"binary field holds unexpected type: %s\", raw == null ? \"null\" : raw.getClass());","typeGuard":"boolean isBinaryRepresentable(Object v) {\n  return v instanceof ByteBuffer || v instanceof byte[] || v instanceof UUID;\n}","tryCatchPattern":"try {\n  byte[] b = structRowData.getBinary(pos);\n} catch (IllegalStateException e) {\n  if (e.getMessage().startsWith(\"Unknown type for binary field\")) {\n    log.error(\"Binary column at pos {} stores incompatible type\", pos, e);\n    throw new SchemaMismatchException(e);\n  }\n  throw e;\n}","preventionTips":["Store binary/fixed columns as ByteBuffer (or byte[]) and uuid as UUID in StructLike rows.","Reject String-encoded binary at write time rather than hoping the reader decodes it."],"tags":["flink","binary","uuid","type-mismatch"],"backgroundTag":"type-mismatch","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"}