apache/cassandra · error · InvalidTypeException
Cannot parse collection value from "%s", at character %d exp
Error message
Cannot parse collection value from "%s", at character %d expecting '%s' but got '%c'
What it means
Thrown by collection codecs' parse() when converting a CQL literal string (e.g. from cqlsh output or a query string) fails because the first non-space character is not the expected opening character ('[' for lists, '{' for sets/maps). The parser reports the position and what it found instead. parse() only accepts well-formed CQL collection literals or null.
Source
Thrown at src/java/org/apache/cassandra/cql3/functions/types/TypeCodec.java:2188
sb.append(getOpeningChar());
int i = 0;
for (E v : value)
{
if (i++ != 0) sb.append(',');
sb.append(eltCodec.format(v));
}
sb.append(getClosingChar());
return sb.toString();
}
@Override
public C parse(String value)
{
if (value == null || value.isEmpty() || value.equalsIgnoreCase("NULL")) return null;
int idx = ParseUtils.skipSpaces(value, 0);
if (value.charAt(idx++) != getOpeningChar())
throw new InvalidTypeException(
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)
{View on GitHub (pinned to 88fd0f6a0e)
Solutions
- Pass a properly delimited CQL collection literal: list/set as [v1,v2] or {v1,v2}, map as {k1:v1,k2:v2}
- Trim and validate the string starts with the codec's opening character before calling parse()
- Bind typed Java collections instead of parsing strings (recommended): use setList/setSet/setMap or the codec's serialize path
- If the input is JSON, convert it to a CQL literal first (e.g. build a List and let the codec format it with format()).
Example fix
// before
List<Integer> l = intListCodec.parse("1,2,3"); // InvalidTypeException
// after
List<Integer> l = intListCodec.parse("[1,2,3]"); Defensive patterns
Strategy: validation
Validate before calling
// before parse
String v = input == null ? null : input.trim();
if (v == null || v.equalsIgnoreCase("null")) return null;
if (!(v.startsWith("[") || v.startsWith("{")))
throw new IllegalArgumentException("Expected CQL collection literal starting with '[' or '{': " + input); Type guard
static boolean isCollectionLiteral(String s) {
if (s == null) return false;
String t = s.trim();
return (t.startsWith("[") && t.endsWith("]")) || (t.startsWith("{") && t.endsWith("}"));
} Try / catch
try {
return codec.parse(literal);
} catch (InvalidTypeException e) {
LOG.warn("Bad collection literal: {}", e.getMessage());
return null;
} Prevention
- Prefer binding typed Java collections over parsing string literals
- When accepting user text, validate the leading '[' or '{' before parse()
- Convert JSON input to Java collections first, then let format() produce the CQL literal
When it happens
Trigger: Calling codec.parse() (or session.prepare/execute paths that parse literals) with a string missing the opening bracket/brace — e.g. "1,2,3" instead of "[1,2,3]", or a quoted/mismatched delimiter like "(1,2,3)".
Common situations: Copying values out of cqlsh without delimiters; passing JSON arrays ("[1,2]" works but "{\"a\":1}" does not for a map); confusing set/map opening char '{' with list '[' after changing column type; empty-ish strings with stray whitespace then a wrong char.
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", invalid CQL value a
- 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/90c105136541065a.
Report an issue: GitHub.