{"record":{"id":"96fdc02f97b71f91","repo":"apache/iceberg","slug":"cannot-convert-to-boolean-value-getclass-getn","errorCode":null,"errorMessage":"Cannot convert to boolean: ${value.getClass().getName()}","messagePattern":"Cannot convert to boolean: (.+?)","errorType":"exception","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"kafka-connect/kafka-connect/src/main/java/org/apache/iceberg/connect/data/RecordConverter.java","lineNumber":486,"sourceCode":"      } 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(\n          \"Cannot convert to BigDecimal: \" + value.getClass().getName());\n    }\n    return bigDecimal.setScale(type.scale(), RoundingMode.HALF_UP);\n  }\n\n  protected boolean convertBoolean(Object value) {\n    if (value instanceof Boolean) {\n      return (boolean) value;\n    } else if (value instanceof String) {\n      return Boolean.parseBoolean((String) value);\n    }\n    throw new IllegalArgumentException(\"Cannot convert to boolean: \" + value.getClass().getName());\n  }\n\n  protected String convertString(Object value) {\n    try {\n      if (value instanceof String) {\n        return (String) value;\n      } else if (value instanceof Number || value instanceof Boolean) {\n        return value.toString();\n      } else if (value instanceof Map || value instanceof List) {\n        return MAPPER.writeValueAsString(value);\n      } else if (value instanceof Struct) {\n        Struct struct = (Struct) value;\n        byte[] data = config.jsonConverter().fromConnectData(null, struct.schema(), struct);\n        return new String(data, StandardCharsets.UTF_8);\n      }\n    } catch (IOException e) {\n      throw new UncheckedIOException(e);\n    }","sourceCodeStart":468,"sourceCodeEnd":504,"githubUrl":"https://github.com/apache/iceberg/blob/86d9c8fc543e7c56c9f624eb725f76c9baff9570/kafka-connect/kafka-connect/src/main/java/org/apache/iceberg/connect/data/RecordConverter.java#L468-L504","documentation":"convertBoolean converts values to Iceberg BooleanType fields: it accepts Boolean directly and String via Boolean.parseBoolean. Note parseBoolean treats any non-\"true\" string as false, so only non-String/non-Boolean classes (Number, byte[], Map, List) throw IllegalArgumentException.","triggerScenarios":"A field mapped to an Iceberg BooleanType column holding a Number, byte[], collection, or other value that is neither Boolean nor String.","commonSituations":"Boolean columns fed 0/1 integer values from producers (a common mismatch — numbers are NOT accepted here); schemaless JSON with mixed types; legacy producers using int flags.","solutions":["Send actual Boolean values (or \"true\"/\"false\" strings) for boolean fields.","If the producer emits 0/1, add an SMT to convert ints to booleans, or change the column to IntegerType.","Change the Iceberg column type to match the actual data type.","Catch IllegalArgumentException to divert records to a DLQ."],"exampleFix":"// before\nrecord.set(\"active\", 1); // int into BooleanType\n// after\nrecord.set(\"active\", true); // or SMT: ReplaceField with cast, or column INTEGER","handlingStrategy":"validation","validationCode":"Object v = record.get(\"active\");\nif (!(v instanceof Boolean) && !(v instanceof String)) {\n  throw new IllegalArgumentException(\"active must be boolean, got \" + v.getClass().getSimpleName());\n}","typeGuard":"boolean isBooleanConvertible(Object v) {\n  return v instanceof Boolean || 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 boolean\")) {\n    sendToDlq(record, e);\n  } else throw e;\n}","preventionTips":["Remember 0/1 integers are NOT accepted — convert flags to real booleans at the producer.","Use Schema.BUILDER for boolean fields so converters preserve the logical type.","Audit legacy topics for int-flag columns mapped to BOOLEAN in Iceberg."],"tags":["kafka-connect","boolean","type-coercion"],"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"}