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);

                try

View on GitHub (pinned to 88fd0f6a0e)

Solutions

  1. Quote string keys with single quotes (and double any embedded quotes) in the literal
  2. Remove stray delimiter characters or fix truncation around the reported index
  3. 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

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


AI-assisted analysis of apache/cassandra@88fd0f6a0e (2026-09-10). Data as JSON: /api/errors/7aa7d617a649fce6. Report an issue: GitHub.