apache/cassandra · error · InvalidTypeException
Cannot parse map value from "%s", invalid CQL value at chara
Error message
Cannot parse map value from "%s", invalid CQL value at character %d
What it means
Thrown while parsing a map literal when the key token cannot be tokenized as a valid CQL value — ParseUtils.skipCQLValue raised an IllegalArgumentException, which the codec wraps in an InvalidTypeException with the offending character index.
Source
Thrown at src/java/org/apache/cassandra/cql3/functions/types/TypeCodec.java:2377
String.format(
"cannot parse map value from \"%s\", at character %d expecting '{' but got '%c'",
value, idx, value.charAt(idx)));
idx = ParseUtils.skipSpaces(value, idx);
if (value.charAt(idx) == '}') return newInstance(0);
Map<K, V> m = new HashMap<>();
while (idx < value.length())
{
int n;
try
{
n = ParseUtils.skipCQLValue(value, idx);
}
catch (IllegalArgumentException e)
{
throw new InvalidTypeException(
String.format(
"Cannot parse map value from \"%s\", invalid CQL value at character %d",
value, idx),
e);
}
K k = keyCodec.parse(value.substring(idx, n));
idx = n;
idx = ParseUtils.skipSpaces(value, idx);
if (value.charAt(idx++) != ':')
throw new InvalidTypeException(
String.format(
"Cannot parse map value from \"%s\", at character %d expecting ':' but got '%c'",
value, idx, value.charAt(idx)));
idx = ParseUtils.skipSpaces(value, idx);
tryView on GitHub (pinned to 88fd0f6a0e)
Solutions
- Quote string keys with single quotes (and double any embedded quotes) in the literal
- Remove stray delimiter characters or fix truncation around the reported index
- Use codec.format(map) to generate the literal instead of concatenating strings
Example fix
// before
mapCodec.parse("{unterminated:'v'}");
// after
mapCodec.parse("{'unterminated':'v'}"); Defensive patterns
Strategy: validation
Validate before calling
// quote string keys before parsing
String safe = keys.stream()
.map(k -> k instanceof String ? "'" + ((String) k).replace("'", "''") + "'" : k.toString())
.collect(Collectors.joining(",", "{", "}"));
mapCodec.parse(safe); Try / catch
try {
Map<K,V> m = mapCodec.parse(value);
} catch (InvalidTypeException e) {
int idx = parseIdx(e.getMessage());
throw new IllegalArgumentException("Bad token at char " + idx + " in: " + value, e);
} Prevention
- Always quote string keys with single quotes in CQL literals
- Double any embedded single quotes ('')
- Avoid hand-built literals; use codec.format()
When it happens
Trigger: Calling MapCodec.parse() with a malformed key in the map literal, e.g. "{unterminated:'a'}", "{:'v'}" (empty key), or a key with bad escaping like "{a\:'v'}".
Common situations: User-supplied map literals pasted from logs with dropped characters; unquoted keys containing CQL delimiters (',', ':', '}'); programmatic string building that forgot to quote string keys.
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 map value from "%s", at character %d expecting
- Cannot parse map value from "%s", at character %d expecting
- Cannot parse map value from "%s", at character %d expecting
- Malformed map value "%s", missing closing '}'
- 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/7aa7d617a649fce6.
Report an issue: GitHub.