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 ',' but got '%c'

What it means

Thrown by collection codecs' parse() when, after consuming an element, the next non-space character is neither the closing character nor a comma, so the literal is structurally malformed. The message reports the character position and the offending character found.

Source

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

                {
                    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);
            }
            throw new InvalidTypeException(
            String.format(
            "Malformed collection value \"%s\", missing closing '%s'", value, getClosingChar()));
        }

        @Override
        public boolean accepts(Object value)
        {
            if (getJavaType().getRawType().isAssignableFrom(value.getClass()))
            {
                // runtime type ok, now check element type
                Collection<?> coll = (Collection<?>) value;

View on GitHub (pinned to 88fd0f6a0e)

Solutions

  1. Use commas between elements: [1,2,3], {a:1,b:2}; ensure no stray spaces-as-separators or semicolons
  2. Convert from JSON/other syntax to CQL literal syntax (map uses ':' key-value separator, not ':')
  3. Quote string elements so special characters don't break delimiter scanning, and build literals via codec format() on a real Java collection instead of concatenation
  4. Sanitize/validate the input string with a regex for the expected shape before calling parse()

Example fix

// before
List<Integer> l = intListCodec.parse("[1 2 3]"); // InvalidTypeException at char 3
// after
List<Integer> l = intListCodec.parse("[1,2,3]");
Defensive patterns

Strategy: validation

Validate before calling

// before parse
String t = input == null ? "" : input.trim();
if (!t.matches("\\[.*\\]|\\{.*\\}"))
    throw new IllegalArgumentException("Not a bracketed CQL collection literal: " + input);
// sanity: no whitespace/semicolon used as separator between elements
if (t.contains(";")) throw new IllegalArgumentException("Use ',' as element separator");

Try / catch

try {
    return codec.parse(literal);
} catch (InvalidTypeException e) {
    LOG.warn("Malformed collection literal (bad separator): {}", e.getMessage());
    return null;
}

Prevention

When it happens

Trigger: Calling parse() with missing or wrong separators, e.g. "[1 2]", "[1;2]", or "{'a':'b' 'c':'d'}" for a map; also happens with unescaped characters inside unquoted elements that swallow the comma position.

Common situations: Hand-built literals from string concatenation with wrong delimiters; values copied from other formats (JSON uses "a":1 vs CQL map a:1, semicolon-separated lists); truncated literals from logs where a quote was stripped.

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/6c77ced71ef17601. Report an issue: GitHub.