{"record":{"id":"05c808113e133198","repo":"apache/iceberg","slug":"cannot-convert-to-long-value-getclass-getname","errorCode":null,"errorMessage":"Cannot convert to long: ${value.getClass().getName()}","messagePattern":"Cannot convert to long: (.+?)","errorType":"exception","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"kafka-connect/kafka-connect/src/main/java/org/apache/iceberg/connect/data/RecordConverter.java","lineNumber":438,"sourceCode":"    return result;\n  }\n\n  protected int convertInt(Object value) {\n    if (value instanceof Number) {\n      return ((Number) value).intValue();\n    } else if (value instanceof String) {\n      return Integer.parseInt((String) value);\n    }\n    throw new IllegalArgumentException(\"Cannot convert to int: \" + value.getClass().getName());\n  }\n\n  protected long convertLong(Object value) {\n    if (value instanceof Number) {\n      return ((Number) value).longValue();\n    } else if (value instanceof String) {\n      return Long.parseLong((String) value);\n    }\n    throw new IllegalArgumentException(\"Cannot convert to long: \" + value.getClass().getName());\n  }\n\n  protected float convertFloat(Object value) {\n    if (value instanceof Number) {\n      return ((Number) value).floatValue();\n    } else if (value instanceof String) {\n      return Float.parseFloat((String) value);\n    }\n    throw new IllegalArgumentException(\"Cannot convert to float: \" + value.getClass().getName());\n  }\n\n  protected double convertDouble(Object value) {\n    if (value instanceof Number) {\n      return ((Number) value).doubleValue();\n    } else if (value instanceof String) {\n      return Double.parseDouble((String) value);\n    }\n    throw new IllegalArgumentException(\"Cannot convert to double: \" + value.getClass().getName());","sourceCodeStart":420,"sourceCodeEnd":456,"githubUrl":"https://github.com/apache/iceberg/blob/86d9c8fc543e7c56c9f624eb725f76c9baff9570/kafka-connect/kafka-connect/src/main/java/org/apache/iceberg/connect/data/RecordConverter.java#L420-L456","documentation":"Conversion failure in RecordConverter.convertLong: the incoming Kafka Connect value for a long-typed field is neither a Number nor a String, so no coercion path applies. The appended class name identifies the value's actual Java type; the topic's schema disagrees with the Iceberg column type.","triggerScenarios":"A field mapped to an Iceberg LongType column carrying a Boolean, byte[], Map, List, or other non-numeric non-string value.","commonSituations":"Producers emitting booleans/objects where the table expects bigint; JSON without schemas where all values become Booleans; nested structs landing in long columns.","solutions":["Emit numeric (or numeric-string) values from the producer for long fields.","Alter the Iceberg column type to match the real value type.","Apply a value transformation SMT to normalize types upstream of the sink.","Route malformed records to a DLQ by catching IllegalArgumentException."],"exampleFix":"// before\nrecord.set(\"ts\", \"2024-01-01T00:00:00\"); // string date into LongType\n// after\nrecord.set(\"ts\", 1704067200000L); // epoch millis","handlingStrategy":"validation","validationCode":"Object v = record.get(\"ts\");\nif (!(v instanceof Number) && !(v instanceof String)) {\n  throw new IllegalArgumentException(\"ts must be numeric, got \" + v.getClass().getSimpleName());\n}","typeGuard":"boolean isLongConvertible(Object v) {\n  return v instanceof Number || v instanceof String;\n}","tryCatchPattern":"try {\n  sink.write(record);\n} catch (IllegalArgumentException e) {\n  if (e.getMessage() != null && e.getMessage().contains(\"Cannot convert to long\")) {\n    sendToDlq(record, e);\n  } else throw e;\n}","preventionTips":["Emit timestamps as epoch millis (long) not formatted date strings.","Enforce producer schemas with the schema registry (int64 fields).","Test conversion of representative payloads against the table schema before rollout."],"tags":["kafka-connect","type-coercion","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-23T08:17:48.524Z"}