{"record":{"id":"e145913270ed22cc","repo":"apache/iceberg","slug":"cannot-convert-to-double-value-getclass-getna","errorCode":null,"errorMessage":"Cannot convert to double: ${value.getClass().getName()}","messagePattern":"Cannot convert to double: (.+?)","errorType":"exception","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"kafka-connect/kafka-connect/src/main/java/org/apache/iceberg/connect/data/RecordConverter.java","lineNumber":456,"sourceCode":"    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());\n  }\n\n  protected BigDecimal convertDecimal(Object value, DecimalType type) {\n    BigDecimal bigDecimal;\n    if (value instanceof BigDecimal) {\n      bigDecimal = (BigDecimal) value;\n    } else if (value instanceof Number) {\n      Number num = (Number) value;\n      Double dbl = num.doubleValue();\n      if (dbl.equals(Math.floor(dbl))) {\n        bigDecimal = BigDecimal.valueOf(num.longValue());\n      } else {\n        bigDecimal = BigDecimal.valueOf(dbl);\n      }\n    } else if (value instanceof String) {\n      bigDecimal = new BigDecimal((String) value);\n    } else {\n      throw new IllegalArgumentException(","sourceCodeStart":438,"sourceCodeEnd":474,"githubUrl":"https://github.com/apache/iceberg/blob/86d9c8fc543e7c56c9f624eb725f76c9baff9570/kafka-connect/kafka-connect/src/main/java/org/apache/iceberg/connect/data/RecordConverter.java#L438-L474","documentation":"convertDouble coerces Connect values to Iceberg DoubleType fields: accepts Number (doubleValue()) and String (Double.parseDouble). Any other class throws IllegalArgumentException with the value's class name.","triggerScenarios":"A field mapped to an Iceberg DoubleType column holding a Boolean, byte[], collection, or other non-numeric non-string value.","commonSituations":"Double columns receiving booleans from schemaless JSON; producer type drift from double to string-encoded data not parseable as a number (which instead throws NumberFormatException deeper in parsing).","solutions":["Fix the producer to emit numbers or numeric strings for double fields.","Adjust the Iceberg schema so the column type matches the data.","Use a transformation to convert values before the sink.","Handle IllegalArgumentException by diverting the record to a DLQ."],"exampleFix":"// before\nrecord.set(\"amount\", new byte[] {1, 2}); // byte[] into DoubleType\n// after\nrecord.set(\"amount\", 42.5d);","handlingStrategy":"validation","validationCode":"Object v = record.get(\"amount\");\nif (!(v instanceof Number) && !(v instanceof String)) {\n  throw new IllegalArgumentException(\"amount must be numeric, got \" + v.getClass().getSimpleName());\n}","typeGuard":"boolean isDoubleConvertible(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 double\")) {\n    sendToDlq(record, e);\n  } else throw e;\n}","preventionTips":["Keep DOUBLE columns fed by double-typed producer fields.","Watch for schemaless JSON converters turning numbers into other wrappers; enable schemas.","Add a payload smoke test per topic before enabling the sink."],"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"}