apache/cassandra · error · InvalidTypeException
Cannot parse collection value from "%s", invalid CQL value a
Error message
Cannot parse collection value from "%s", invalid CQL value at character %d
What it means
Thrown by collection codecs' parse() when an element of the collection literal is not a syntactically valid CQL value. The underlying ParseUtils.skipCQLValue scanner throws IllegalArgumentException, which the codec wraps in an InvalidTypeException identifying the offending character position.
Source
Thrown at src/java/org/apache/cassandra/cql3/functions/types/TypeCodec.java:2207
String.format(
"Cannot parse collection value from \"%s\", at character %d expecting '%s' but got '%c'",
value, idx, getOpeningChar(), value.charAt(idx)));
idx = ParseUtils.skipSpaces(value, idx);
if (value.charAt(idx) == getClosingChar()) return newInstance(0);
C l = newInstance(10);
while (idx < value.length())
{
int n;
try
{
n = ParseUtils.skipCQLValue(value, idx);
}
catch (IllegalArgumentException e)
{
throw new InvalidTypeException(
String.format(
"Cannot parse collection value from \"%s\", invalid CQL value at character %d",
value, idx),
e);
}
l.add(eltCodec.parse(value.substring(idx, n)));
idx = n;
idx = ParseUtils.skipSpaces(value, idx);
if (value.charAt(idx) == getClosingChar()) return l;
if (value.charAt(idx++) != ',')
throw new InvalidTypeException(
String.format(
"Cannot parse collection value from \"%s\", at character %d expecting ',' but got '%c'",
value, idx, value.charAt(idx)));
idx = ParseUtils.skipSpaces(value, idx);View on GitHub (pinned to 88fd0f6a0e)
Solutions
- Quote string elements with single quotes and escape internal quotes by doubling them: ['it''s']
- Validate/escape user input before embedding it in a CQL literal (use the element codec's format() on each element instead of string concatenation)
- Bind typed values instead of parsing raw strings to bypass literal syntax entirely
- Remove empty elements and trailing commas from the literal
Example fix
// before
List<String> l = textListCodec.parse("[a,b]"); // 'a' is invalid CQL value for text
// after
List<String> l = textListCodec.parse("['a','b']"); Defensive patterns
Strategy: validation
Validate before calling
// before parse: build literal via element codec instead of raw interpolation
String literal = elements.stream()
.map(e -> e == null ? "null" : "'" + e.replace("'", "''") + "'")
.collect(Collectors.joining(",", "[", "]")); Try / catch
try {
return codec.parse(literal);
} catch (InvalidTypeException e) {
LOG.warn("Invalid CQL value in literal at reported position: {}", e.getMessage());
return null;
} Prevention
- Never concatenate unescaped user input into CQL literals
- Escape single quotes by doubling them in string elements
- Build literals with codec.format() on typed Java values instead of string manipulation
When it happens
Trigger: Calling parse() on a collection literal containing a malformed element, e.g. an unquoted string containing special characters ( [a] for list<text>), unterminated quoted string ['abc], or an invalid numeric literal like [1.2.3].
Common situations: String elements with commas, brackets or quotes that are not single-quote escaped; user-supplied input interpolated directly into literals; values copied from JSON or CSV without escaping; empty elements like [,] or trailing commas.
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 collection value from "%s", at character %d exp
- Cannot parse collection value from "%s", at character %d exp
- Cannot parse 32-bits int value from "%s"
- Cannot parse timestamp value from "%s"
- Cannot parse date value from "%s"
AI-assisted analysis of apache/cassandra@88fd0f6a0e (2026-09-10).
Data as JSON: /api/errors/0786a8c72af4f39f.
Report an issue: GitHub.