{"record":{"id":"1b4a5756a7ac22b4","repo":"apache/iceberg","slug":"cannot-convert-to-int-value-getclass-getname","errorCode":null,"errorMessage":"Cannot convert to int: ${value.getClass().getName()}","messagePattern":"Cannot convert to int: (.+?)","errorType":"exception","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"kafka-connect/kafka-connect/src/main/java/org/apache/iceberg/connect/data/RecordConverter.java","lineNumber":429,"sourceCode":"    int valueFieldId = type.fields().get(1).fieldId();\n    Type keyType = type.keyType();\n    Type valueType = type.valueType();\n    Map<Object, Object> result = Maps.newHashMapWithExpectedSize(map.size());\n    map.forEach(\n        (k, v) ->\n            result.put(\n                convertValue(k, keyType, keyFieldId, schemaUpdateConsumer),\n                convertValue(v, valueType, valueFieldId, schemaUpdateConsumer)));\n    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());","sourceCodeStart":411,"sourceCodeEnd":447,"githubUrl":"https://github.com/apache/iceberg/blob/86d9c8fc543e7c56c9f624eb725f76c9baff9570/kafka-connect/kafka-connect/src/main/java/org/apache/iceberg/connect/data/RecordConverter.java#L411-L447","documentation":"convertInt coerces Connect values to Iceberg Integer fields: it accepts Number (via intValue()) and String (via Integer.parseInt). Anything else — Boolean, byte[], List, Map, etc. — throws IllegalArgumentException naming the value's class.","triggerScenarios":"Writing a record whose field mapped to an Iceberg IntegerType column holds a Boolean, byte[], collection, or other non-numeric non-string value.","commonSituations":"JSON payloads with booleans/objects in integer fields; schema registry schema mismatch; producer type changed from int to boolean without updating the table schema.","solutions":["Fix the producer so the field sends a numeric or numeric-string value.","Change the Iceberg column type to match the actual value type (e.g. BooleanType).","Pre-clean the value in a transform/SMT to convert or default it before the sink.","Catch IllegalArgumentException and route the record to a DLQ."],"exampleFix":"// before\nrecord.set(\"count\", true); // boolean into IntegerType\n// after\nrecord.set(\"count\", 1); // or change column to BOOLEAN","handlingStrategy":"validation","validationCode":"Object v = record.get(\"count\");\nif (!(v instanceof Number) && !(v instanceof String)) {\n  throw new IllegalArgumentException(\"count must be numeric, got \" + v.getClass().getSimpleName());\n}","typeGuard":"boolean isIntConvertible(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 int\")) {\n    sendToDlq(record, e);\n  } else throw e;\n}","preventionTips":["Cast numeric fields in producer schemas to int32 rather than relying on JSON loose typing.","Ensure boolean flags are not mapped to integer Iceberg columns.","Add unit tests covering producer value types against the table schema."],"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"}