apache/cassandra · error · InvalidTypeException
Cannot parse boolean value from "%s"
Error message
Cannot parse boolean value from "%s"
What it means
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.
Source
Thrown at src/java/org/apache/cassandra/cql3/functions/types/TypeCodec.java:1257
private BooleanCodec()
{
super(DataType.cboolean());
}
@Override
public int serializedSize()
{
return 1;
}
@Override
public Boolean parse(String value)
{
if (value == null || value.isEmpty() || value.equalsIgnoreCase("NULL")) return null;
if (value.equalsIgnoreCase(Boolean.FALSE.toString())) return false;
if (value.equalsIgnoreCase(Boolean.TRUE.toString())) return true;
throw new InvalidTypeException(
String.format("Cannot parse boolean value from \"%s\"", value));
}
@Override
public String format(Boolean value)
{
if (value == null) return "NULL";
return value ? "true" : "false";
}
@Override
public ByteBuffer serializeNoBoxing(boolean value, ProtocolVersion protocolVersion)
{
return value ? TRUE.duplicate() : FALSE.duplicate();
}
@Override
public boolean deserializeNoBoxing(ByteBuffer bytes, ProtocolVersion protocolVersion)View on GitHub (pinned to 88fd0f6a0e)
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.
Example fix
// before
booleanCodec.parse("yes"); // throws
// after
boolean b = "yes".equalsIgnoreCase("true") || "yes".equals("1") || "yes".equalsIgnoreCase("yes");
booleanCodec.parse(Boolean.toString(b)); // "true" Defensive patterns
Strategy: validation
Validate before calling
static String toCqlBooleanLiteral(String v) {
if (v == null || v.isEmpty() || v.equalsIgnoreCase("NULL")) return null;
if (v.equalsIgnoreCase("true") || v.equals("1") || v.equalsIgnoreCase("yes") || v.equalsIgnoreCase("y")) return "true";
if (v.equalsIgnoreCase("false") || v.equals("0") || v.equalsIgnoreCase("no") || v.equalsIgnoreCase("n")) return "false";
throw new IllegalArgumentException("Not a boolean: " + v);
} Type guard
boolean isBooleanLiteral(String v) {
return "true".equalsIgnoreCase(v) || "false".equalsIgnoreCase(v);
} Try / catch
try {
return booleanCodec.parse(raw);
} catch (InvalidTypeException e) {
return booleanCodec.parse(toCqlBooleanLiteral(raw));
} Prevention
- 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).
When it happens
Trigger: Calling booleanCodec.parse(value) with values like "yes", "no", "1", "0", "Y", "T", "on", or any non-boolean token.
Common situations: 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.
Understand the failure class
Background: "Invalid ... format", "must be in format X", "does not look like a ..." — invalid argument format errors across CLI tools and libraries — this error's family across 17 libraries.
Related errors
- Cannot parse 64-bits long value from "%s"
- Invalid boolean value, expecting 1 byte but got
- Cannot parse decimal value from "%s"
- Cannot parse 64-bits double value from "%s"
- text or varchar values must be enclosed by single quotes
AI-assisted analysis of apache/cassandra@88fd0f6a0e (2026-09-10).
Data as JSON: /api/errors/93fa974647b31b8e.
Report an issue: GitHub.