{"record":{"id":"3289407fd1eb74b8","repo":"apache/iceberg","slug":"cannot-convert-to-binary-value-getclass-getna","errorCode":null,"errorMessage":"Cannot convert to binary: ${value.getClass().getName()}","messagePattern":"Cannot convert to binary: (.+?)","errorType":"exception","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"kafka-connect/kafka-connect/src/main/java/org/apache/iceberg/connect/data/RecordConverter.java","lineNumber":536,"sourceCode":"    if (FileFormat.PARQUET\n        .name()\n        .toLowerCase(Locale.ROOT)\n        .equals(config.writeProps().get(TableProperties.DEFAULT_FILE_FORMAT))) {\n      return UUIDUtil.convert(uuid);\n    } else {\n      return uuid;\n    }\n  }\n\n  protected ByteBuffer convertBase64Binary(Object value) {\n    if (value instanceof String) {\n      return ByteBuffer.wrap(Base64.getDecoder().decode((String) value));\n    } else if (value instanceof byte[]) {\n      return ByteBuffer.wrap((byte[]) value);\n    } else if (value instanceof ByteBuffer) {\n      return (ByteBuffer) value;\n    }\n    throw new IllegalArgumentException(\"Cannot convert to binary: \" + value.getClass().getName());\n  }\n\n  @SuppressWarnings(\"JavaUtilDate\")\n  protected LocalDate convertDateValue(Object value) {\n    if (value instanceof Number) {\n      int days = ((Number) value).intValue();\n      return DateTimeUtil.dateFromDays(days);\n    } else if (value instanceof String) {\n      return LocalDate.parse((String) value);\n    } else if (value instanceof LocalDate) {\n      return (LocalDate) value;\n    } else if (value instanceof Date) {\n      int days = (int) (((Date) value).getTime() / 1000 / 60 / 60 / 24);\n      return DateTimeUtil.dateFromDays(days);\n    }\n    throw new ConnectException(\"Cannot convert date: \" + value);\n  }\n","sourceCodeStart":518,"sourceCodeEnd":554,"githubUrl":"https://github.com/apache/iceberg/blob/86d9c8fc543e7c56c9f624eb725f76c9baff9570/kafka-connect/kafka-connect/src/main/java/org/apache/iceberg/connect/data/RecordConverter.java#L518-L554","documentation":"RecordConverter.convertBase64Binary throws this IllegalArgumentException when a value targeted at an Iceberg binary column is neither a Base64-encoded String, byte[], nor ByteBuffer. The converter cannot wrap the given type into the expected ByteBuffer representation.","triggerScenarios":"A binary Iceberg field receives a Number, Boolean, Map, List, or Struct from the Kafka Connect record instead of String/byte[]/ByteBuffer.","commonSituations":"Kafka Connect schema declares a field as int/struct while the Iceberg table expects binary; JSON-encoded binary arrives as a nested object; a schema evolution changed the field type on the producer side but not the Iceberg table (or vice versa).","solutions":["Declare the Connect field as bytes (SchemaBuilder.bytes()) or string (Base64) so the converter can decode it","Wrap the raw value in ByteBuffer or byte[] via an SMT before it reaches the sink","Inspect the offending value's actual class in the message and align the Iceberg column type with it","If the data is really a struct/list, change the Iceberg table column type instead of binary"],"exampleFix":"// before\nSchema bad = SchemaBuilder.int64().build(); // long value -> cannot convert to binary\n// after\nSchema good = SchemaBuilder.bytes().build(); // byte[]/ByteBuffer accepted","handlingStrategy":"type-guard","validationCode":"if (value != null && !(value instanceof String || value instanceof byte[] || value instanceof ByteBuffer)) {\n  throw new IllegalStateException(\"Binary field must be Base64 String, byte[], or ByteBuffer, got: \" + value.getClass());\n}","typeGuard":"static boolean isBinaryCompatible(Object v) {\n  return v == null || v instanceof String || v instanceof byte[] || v instanceof ByteBuffer;\n}","tryCatchPattern":"try {\n  converter.convertValue(value, Types.BinaryType.get());\n} catch (IllegalArgumentException e) {\n  log.error(\"Binary conversion failed for class: \" + e.getMessage(), e);\n  // DLQ record or convert via ByteBuffer.wrap(String.valueOf(value).getBytes(StandardCharsets.UTF_8))\n}","preventionTips":["Map binary columns to bytes or Base64 string Connect schemas","Validate schemas against the Iceberg table at connector startup","Avoid passing structs/lists into binary columns","Keep Base64 encoding consistent between producer and sink"],"tags":["kafka-connect","type-mismatch","binary"],"backgroundTag":"type-mismatch","analyzedSha":"86d9c8fc543e7c56c9f624eb725f76c9baff9570","analyzedAt":"2026-09-12T00:46:39.097Z","contentChangedAt":"2026-09-12T00:46:39.097Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}