{"record":{"id":"93fa974647b31b8e","repo":"apache/cassandra","slug":"cannot-parse-boolean-value-from-s","errorCode":null,"errorMessage":"Cannot parse boolean value from \"%s\"","messagePattern":"Cannot parse boolean value from \"(.+?)\"","errorType":"validation","errorClass":"InvalidTypeException","httpStatus":null,"severity":"error","filePath":"src/java/org/apache/cassandra/cql3/functions/types/TypeCodec.java","lineNumber":1257,"sourceCode":"        private BooleanCodec()\n        {\n            super(DataType.cboolean());\n        }\n\n        @Override\n        public int serializedSize()\n        {\n            return 1;\n        }\n\n        @Override\n        public Boolean parse(String value)\n        {\n            if (value == null || value.isEmpty() || value.equalsIgnoreCase(\"NULL\")) return null;\n            if (value.equalsIgnoreCase(Boolean.FALSE.toString())) return false;\n            if (value.equalsIgnoreCase(Boolean.TRUE.toString())) return true;\n\n            throw new InvalidTypeException(\n            String.format(\"Cannot parse boolean value from \\\"%s\\\"\", value));\n        }\n\n        @Override\n        public String format(Boolean value)\n        {\n            if (value == null) return \"NULL\";\n            return value ? \"true\" : \"false\";\n        }\n\n        @Override\n        public ByteBuffer serializeNoBoxing(boolean value, ProtocolVersion protocolVersion)\n        {\n            return value ? TRUE.duplicate() : FALSE.duplicate();\n        }\n\n        @Override\n        public boolean deserializeNoBoxing(ByteBuffer bytes, ProtocolVersion protocolVersion)","sourceCodeStart":1239,"sourceCodeEnd":1275,"githubUrl":"https://github.com/apache/cassandra/blob/88fd0f6a0eaed8943f05ac9e8f947882b8ddc8f1/src/java/org/apache/cassandra/cql3/functions/types/TypeCodec.java#L1239-L1275","documentation":"The boolean codec's parse() only accepts the exact literals \"true\" or \"false\" (case-insensitive) or NULL. Any other spelling — \"yes\", \"1\", \"0\", \"t\", \"on\" — is a valid concept but not valid CQL boolean literal syntax, so it throws InvalidTypeException.","triggerScenarios":"Calling booleanCodec.parse(value) with values like \"yes\", \"no\", \"1\", \"0\", \"Y\", \"T\", \"on\", or any non-boolean token.","commonSituations":"Importing booleans from CSV/JSON where truthiness is encoded as 1/0 or yes/no; config-driven CQL literal generation using language-specific boolean strings; hand-written CQL in cqlsh using non-standard literals.","solutions":["Normalize the value before parsing: Boolean.parseBoolean for 1/0/yes/no mapping, then pass Boolean.toString(b).","Map \"1\"→\"true\" and \"0\"→\"false\" explicitly at the data-ingestion boundary.","Use codec.format(booleanValue) instead of parsing strings when you have a real boolean."],"exampleFix":"// before\nbooleanCodec.parse(\"yes\"); // throws\n// after\nboolean b = \"yes\".equalsIgnoreCase(\"true\") || \"yes\".equals(\"1\") || \"yes\".equalsIgnoreCase(\"yes\");\nbooleanCodec.parse(Boolean.toString(b)); // \"true\"","handlingStrategy":"validation","validationCode":"static String toCqlBooleanLiteral(String v) {\n    if (v == null || v.isEmpty() || v.equalsIgnoreCase(\"NULL\")) return null;\n    if (v.equalsIgnoreCase(\"true\") || v.equals(\"1\") || v.equalsIgnoreCase(\"yes\") || v.equalsIgnoreCase(\"y\")) return \"true\";\n    if (v.equalsIgnoreCase(\"false\") || v.equals(\"0\") || v.equalsIgnoreCase(\"no\") || v.equalsIgnoreCase(\"n\")) return \"false\";\n    throw new IllegalArgumentException(\"Not a boolean: \" + v);\n}","typeGuard":"boolean isBooleanLiteral(String v) {\n    return \"true\".equalsIgnoreCase(v) || \"false\".equalsIgnoreCase(v);\n}","tryCatchPattern":"try {\n    return booleanCodec.parse(raw);\n} catch (InvalidTypeException e) {\n    return booleanCodec.parse(toCqlBooleanLiteral(raw));\n}","preventionTips":["Convert truthy encodings (1/0, yes/no, Y/N) to true/false at the ingestion boundary.","Use codec.format(true/false) with real booleans instead of parsing strings.","Document that CQL booleans accept only true/false literals (case-insensitive)."],"tags":["cql","boolean","codec","number-parsing"],"backgroundTag":"invalid-argument-format","analyzedSha":"88fd0f6a0eaed8943f05ac9e8f947882b8ddc8f1","analyzedAt":"2026-09-10T07:29:22.284Z","contentChangedAt":"2026-09-10T07:29:22.284Z","schemaVersion":2},"datasetVersion":"2026-09-14T16:17:12.679Z"}