alibaba/DataX · error · RuntimeException
Failed to cast %s to Boolean
Error message
Failed to cast %s to Boolean
What it means
boolColumnMapper(Object o) in gdbreader converts Integer (non-zero -> true), Long (non-zero -> true), Boolean, and String (via Boolean.valueOf) to a BoolColumn. Any other type — Double, Float, Date, List — triggers this RuntimeException with the class name.
Source
Thrown at gdbreader/src/main/java/com/alibaba/datax/plugin/reader/gdbreader/mapping/ValueType.java:114
} else {
throw new RuntimeException("Failed to cast " + o.getClass() + " to Double");
}
return new DoubleColumn(v);
}
private static BoolColumn boolColumnMapper(Object o) {
boolean v;
if (o instanceof Integer) {
v = ((int) o != 0);
} else if (o instanceof Long) {
v = ((long) o != 0);
} else if (o instanceof Boolean) {
v = (boolean) o;
} else if (o instanceof String) {
v = Boolean.valueOf((String) o);
} else {
throw new RuntimeException("Failed to cast " + o.getClass() + " to Boolean");
}
return new BoolColumn(v);
}
private static StringColumn stringColumnMapper(Object o) {
if (o instanceof String) {
return new StringColumn((String) o);
} else {
return new StringColumn(String.valueOf(o));
}
}
}
}
View on GitHub (pinned to 80ec23d5c5)
Solutions
- Re-declare the column as its real type ('double'/'long'/'string') in the gdbreader mapping
- If the property is genuinely 0/1, re-store it as int in GDB so the Integer branch applies
- For multi-valued properties, read the single-cardinality variant or map to string
Example fix
// before
{"columnName": "flag", "Type": "boolean"}
// after
{"columnName": "flag", "Type": "double"} Defensive patterns
Strategy: type-guard
Type guard
static boolean mapsToBoolean(Object o) {
return o instanceof Integer || o instanceof Long || o instanceof Boolean || o instanceof String;
// beware: Boolean.valueOf("1") is false — validate string content separately
} Try / catch
catch (RuntimeException e) {
if (e.getMessage() != null && e.getMessage().contains(" to Boolean")) {
// the class in the message (often Double or Date) cannot map; fix column Type
}
throw e;
} Prevention
- Declare boolean only for true boolean properties; map 0/1 floats as double/long instead
- Remember Boolean.valueOf never throws — non-boolean strings silently become false; validate upstream
When it happens
Trigger: Column declared 'boolean' in the reader mapping but the GDB property is a Float/Double (e.g. 1.0) or a temporal/complex type. Note Boolean.valueOf(String) never throws — any string silently maps (numeric strings like "1" become false), so this error comes only from non-handled object types.
Common situations: Numbers stored as double in GDB mapped to boolean; multi-cardinality properties arriving as collections; java.util.Date properties; version changes in the GDB client altering returned numeric types (Integer -> Double).
Related errors
- Failed to cast %s to Long
- Failed to cast %s to Double
- File not found: ${name}
- to or from missed in edge
- id or label missed
AI-assisted analysis of alibaba/DataX@80ec23d5c5 (2026-08-14).
Data as JSON: /api/errors/dcd4445b49f68680.
Report an issue: GitHub.