apache/cassandra · error · InvalidTypeException

Cannot parse map value from "%s", at character %d expecting

Error message

Cannot parse map value from "%s", at character %d expecting ',' but got '%c'

What it means

Thrown while parsing a map literal when, after finishing an entry, the next non-space character is neither '}' (end of map) nor ',' (entry separator). The parser reports the offending character, indicating entries are separated by an invalid token.

Source

Thrown at src/java/org/apache/cassandra/cql3/functions/types/TypeCodec.java:2416

                }
                catch (IllegalArgumentException e)
                {
                    throw new InvalidTypeException(
                    String.format(
                    "Cannot parse map value from \"%s\", invalid CQL value at character %d",
                    value, idx),
                    e);
                }

                V v = valueCodec.parse(value.substring(idx, n));
                idx = n;

                m.put(k, v);

                idx = ParseUtils.skipSpaces(value, idx);
                if (value.charAt(idx) == '}') return m;
                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);
            }
            throw new InvalidTypeException(
            String.format("Malformed map value \"%s\", missing closing '}'", value));
        }

        @Override
        public String format(Map<K, V> value)
        {
            if (value == null) return "NULL";
            StringBuilder sb = new StringBuilder();
            sb.append('{');
            int i = 0;
            for (Map.Entry<K, V> e : value.entrySet())

View on GitHub (pinned to 88fd0f6a0e)

Solutions

  1. Separate map entries with ',' only
  2. Verify the overall shape {k1:v1,k2:v2} before parsing
  3. Generate the literal with codec.format() instead of manual concatenation

Example fix

// before
mapCodec.parse("{1:'a';2:'b'}");
// after
mapCodec.parse("{1:'a',2:'b'}");
Defensive patterns

Strategy: validation

Validate before calling

if (value.contains(";"))
    throw new IllegalArgumentException("Separate map entries with ',': " + value);
mapCodec.parse(value);

Try / catch

try {
    mapCodec.parse(value);
} catch (InvalidTypeException e) {
    throw new IllegalArgumentException("Entries must be comma-separated: " + value, e);
}

Prevention

When it happens

Trigger: Calling MapCodec.parse() with wrong entry separators such as "{1:'a';2:'b'}" (semicolon), "{1:'a' 2:'b'}" (missing separator), or a newline where a comma is expected.

Common situations: Literals copied from JSON or another language using ';'/newline separators; template-generated strings with the wrong join character; whitespace formatting that dropped the comma.

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/20bb7c2111a63459. Report an issue: GitHub.