{"record":{"id":"dcd4445b49f68680","repo":"alibaba/DataX","slug":"failed-to-cast-s-to-boolean","errorCode":null,"errorMessage":"Failed to cast %s to Boolean","messagePattern":"Failed to cast (.+?) to Boolean","errorType":"exception","errorClass":"RuntimeException","httpStatus":null,"severity":"error","filePath":"gdbreader/src/main/java/com/alibaba/datax/plugin/reader/gdbreader/mapping/ValueType.java","lineNumber":114,"sourceCode":"            } else {\n                throw new RuntimeException(\"Failed to cast \" + o.getClass() + \" to Double\");\n            }\n\n            return new DoubleColumn(v);\n        }\n\n        private static BoolColumn boolColumnMapper(Object o) {\n            boolean v;\n            if (o instanceof Integer) {\n                v = ((int) o != 0);\n            } else if (o instanceof Long) {\n                v = ((long) o != 0);\n            } else if (o instanceof Boolean) {\n                v = (boolean) o;\n            } else if (o instanceof String) {\n                v = Boolean.valueOf((String) o);\n            } else {\n                throw new RuntimeException(\"Failed to cast \" + o.getClass() + \" to Boolean\");\n            }\n\n            return new BoolColumn(v);\n        }\n\n        private static StringColumn stringColumnMapper(Object o) {\n            if (o instanceof String) {\n                return new StringColumn((String) o);\n            } else {\n                return new StringColumn(String.valueOf(o));\n            }\n        }\n    }\n}\n","sourceCodeStart":96,"sourceCodeEnd":129,"githubUrl":"https://github.com/alibaba/DataX/blob/80ec23d5c5328eb90ca364d2749e92dfaf44541e/gdbreader/src/main/java/com/alibaba/datax/plugin/reader/gdbreader/mapping/ValueType.java#L96-L129","documentation":"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.","triggerScenarios":"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.","commonSituations":"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).","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"],"exampleFix":"// before\n{\"columnName\": \"flag\", \"Type\": \"boolean\"}\n// after\n{\"columnName\": \"flag\", \"Type\": \"double\"}","handlingStrategy":"type-guard","validationCode":null,"typeGuard":"static boolean mapsToBoolean(Object o) {\n    return o instanceof Integer || o instanceof Long || o instanceof Boolean || o instanceof String;\n    // beware: Boolean.valueOf(\"1\") is false — validate string content separately\n}","tryCatchPattern":"catch (RuntimeException e) {\n    if (e.getMessage() != null && e.getMessage().contains(\" to Boolean\")) {\n        // the class in the message (often Double or Date) cannot map; fix column Type\n    }\n    throw e;\n}","preventionTips":["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"],"tags":["gdb","gremlin","type-mapping","datax"],"backgroundTag":null,"analyzedSha":"80ec23d5c5328eb90ca364d2749e92dfaf44541e","analyzedAt":"2026-08-14T15:33:51.187Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}