apache/iceberg · error · IllegalArgumentException
Cannot convert to boolean
Error message
Cannot convert to boolean: ${value.getClass().getName()} What it means
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.
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.
Example fix
// before
record.set("active", 1); // int into BooleanType
// after
record.set("active", true); // or SMT: ReplaceField with cast, or column INTEGER Defensive patterns
Strategy: validation
Validate before calling
Object v = record.get("active");
if (!(v instanceof Boolean) && !(v instanceof String)) {
throw new IllegalArgumentException("active must be boolean, got " + v.getClass().getSimpleName());
} Type guard
boolean isBooleanConvertible(Object v) {
return v instanceof Boolean || v instanceof String;
} Try / catch
try {
sink.write(record);
} catch (IllegalArgumentException e) {
if (e.getMessage() != null && e.getMessage().contains("Cannot convert to boolean")) {
sendToDlq(record, e);
} else throw e;
} Prevention
- 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.
When it happens
Trigger: A field mapped to an Iceberg BooleanType column holding a Number, byte[], collection, or other value that is neither Boolean nor String.
Common situations: 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.
Understand the failure class
Background: Type mismatch errors: IllegalArgumentException, TypeError and type guards across 150 open-source libraries — this error's family across 150 libraries.
Related errors
- Cannot convert to BigDecimal
- Cannot convert to double
- Cannot convert to float
- Cannot convert to int
- Cannot convert to long
AI-assisted analysis of apache/iceberg@86d9c8fc54 (2026-09-12).
Data as JSON: /api/errors/96fdc02f97b71f91.
Report an issue: GitHub.
Appendix: source
Thrown at kafka-connect/kafka-connect/src/main/java/org/apache/iceberg/connect/data/RecordConverter.java:486
} else {
bigDecimal = BigDecimal.valueOf(dbl);
}
} else if (value instanceof String) {
bigDecimal = new BigDecimal((String) value);
} else {
throw new IllegalArgumentException(
"Cannot convert to BigDecimal: " + value.getClass().getName());
}
return bigDecimal.setScale(type.scale(), RoundingMode.HALF_UP);
}
protected boolean convertBoolean(Object value) {
if (value instanceof Boolean) {
return (boolean) value;
} else if (value instanceof String) {
return Boolean.parseBoolean((String) value);
}
throw new IllegalArgumentException("Cannot convert to boolean: " + value.getClass().getName());
}
protected String convertString(Object value) {
try {
if (value instanceof String) {
return (String) value;
} else if (value instanceof Number || value instanceof Boolean) {
return value.toString();
} else if (value instanceof Map || value instanceof List) {
return MAPPER.writeValueAsString(value);
} else if (value instanceof Struct) {
Struct struct = (Struct) value;
byte[] data = config.jsonConverter().fromConnectData(null, struct.schema(), struct);
return new String(data, StandardCharsets.UTF_8);
}
} catch (IOException e) {
throw new UncheckedIOException(e);
}View on GitHub (pinned to 86d9c8fc54)