{"record":{"id":"0786a8c72af4f39f","repo":"apache/cassandra","slug":"cannot-parse-collection-value-from-s-invalid-c","errorCode":null,"errorMessage":"Cannot parse collection value from \"%s\", invalid CQL value at character %d","messagePattern":"Cannot parse collection value from \"(.+?)\", invalid CQL value at character (.+?)","errorType":"exception","errorClass":"InvalidTypeException","httpStatus":null,"severity":"error","filePath":"src/java/org/apache/cassandra/cql3/functions/types/TypeCodec.java","lineNumber":2207,"sourceCode":"                String.format(\n                \"Cannot parse collection value from \\\"%s\\\", at character %d expecting '%s' but got '%c'\",\n                value, idx, getOpeningChar(), value.charAt(idx)));\n\n            idx = ParseUtils.skipSpaces(value, idx);\n\n            if (value.charAt(idx) == getClosingChar()) return newInstance(0);\n\n            C l = newInstance(10);\n            while (idx < value.length())\n            {\n                int n;\n                try\n                {\n                    n = ParseUtils.skipCQLValue(value, idx);\n                }\n                catch (IllegalArgumentException e)\n                {\n                    throw new InvalidTypeException(\n                    String.format(\n                    \"Cannot parse collection value from \\\"%s\\\", invalid CQL value at character %d\",\n                    value, idx),\n                    e);\n                }\n\n                l.add(eltCodec.parse(value.substring(idx, n)));\n                idx = n;\n\n                idx = ParseUtils.skipSpaces(value, idx);\n                if (value.charAt(idx) == getClosingChar()) return l;\n                if (value.charAt(idx++) != ',')\n                    throw new InvalidTypeException(\n                    String.format(\n                    \"Cannot parse collection value from \\\"%s\\\", at character %d expecting ',' but got '%c'\",\n                    value, idx, value.charAt(idx)));\n\n                idx = ParseUtils.skipSpaces(value, idx);","sourceCodeStart":2189,"sourceCodeEnd":2225,"githubUrl":"https://github.com/apache/cassandra/blob/88fd0f6a0eaed8943f05ac9e8f947882b8ddc8f1/src/java/org/apache/cassandra/cql3/functions/types/TypeCodec.java#L2189-L2225","documentation":"Thrown by collection codecs' parse() when an element of the collection literal is not a syntactically valid CQL value. The underlying ParseUtils.skipCQLValue scanner throws IllegalArgumentException, which the codec wraps in an InvalidTypeException identifying the offending character position.","triggerScenarios":"Calling parse() on a collection literal containing a malformed element, e.g. an unquoted string containing special characters ( [a] for list<text>), unterminated quoted string ['abc], or an invalid numeric literal like [1.2.3].","commonSituations":"String elements with commas, brackets or quotes that are not single-quote escaped; user-supplied input interpolated directly into literals; values copied from JSON or CSV without escaping; empty elements like [,] or trailing commas.","solutions":["Quote string elements with single quotes and escape internal quotes by doubling them: ['it''s']","Validate/escape user input before embedding it in a CQL literal (use the element codec's format() on each element instead of string concatenation)","Bind typed values instead of parsing raw strings to bypass literal syntax entirely","Remove empty elements and trailing commas from the literal"],"exampleFix":"// before\nList<String> l = textListCodec.parse(\"[a,b]\"); // 'a' is invalid CQL value for text\n// after\nList<String> l = textListCodec.parse(\"['a','b']\");","handlingStrategy":"validation","validationCode":"// before parse: build literal via element codec instead of raw interpolation\nString literal = elements.stream()\n    .map(e -> e == null ? \"null\" : \"'\" + e.replace(\"'\", \"''\") + \"'\")\n    .collect(Collectors.joining(\",\", \"[\", \"]\"));","typeGuard":null,"tryCatchPattern":"try {\n    return codec.parse(literal);\n} catch (InvalidTypeException e) {\n    LOG.warn(\"Invalid CQL value in literal at reported position: {}\", e.getMessage());\n    return null;\n}","preventionTips":["Never concatenate unescaped user input into CQL literals","Escape single quotes by doubling them in string elements","Build literals with codec.format() on typed Java values instead of string manipulation"],"tags":["cassandra","java-driver","parsing","cql-literal"],"backgroundTag":"invalid-argument-format","analyzedSha":"88fd0f6a0eaed8943f05ac9e8f947882b8ddc8f1","analyzedAt":"2026-09-10T07:29:22.284Z","contentChangedAt":"2026-09-10T07:29:22.284Z","schemaVersion":2},"datasetVersion":"2026-09-14T16:17:12.679Z"}