{"record":{"id":"90c105136541065a","repo":"apache/cassandra","slug":"cannot-parse-collection-value-from-s-at-charac","errorCode":null,"errorMessage":"Cannot parse collection value from \"%s\", at character %d expecting '%s' but got '%c'","messagePattern":"Cannot parse collection value from \"(.+?)\", at character (.+?) expecting '(.+?)' but got '%c'","errorType":"exception","errorClass":"InvalidTypeException","httpStatus":null,"severity":"error","filePath":"src/java/org/apache/cassandra/cql3/functions/types/TypeCodec.java","lineNumber":2188,"sourceCode":"            sb.append(getOpeningChar());\n            int i = 0;\n            for (E v : value)\n            {\n                if (i++ != 0) sb.append(',');\n                sb.append(eltCodec.format(v));\n            }\n            sb.append(getClosingChar());\n            return sb.toString();\n        }\n\n        @Override\n        public C parse(String value)\n        {\n            if (value == null || value.isEmpty() || value.equalsIgnoreCase(\"NULL\")) return null;\n\n            int idx = ParseUtils.skipSpaces(value, 0);\n            if (value.charAt(idx++) != getOpeningChar())\n                throw new InvalidTypeException(\n                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                {","sourceCodeStart":2170,"sourceCodeEnd":2206,"githubUrl":"https://github.com/apache/cassandra/blob/88fd0f6a0eaed8943f05ac9e8f947882b8ddc8f1/src/java/org/apache/cassandra/cql3/functions/types/TypeCodec.java#L2170-L2206","documentation":"Thrown by collection codecs' parse() when converting a CQL literal string (e.g. from cqlsh output or a query string) fails because the first non-space character is not the expected opening character ('[' for lists, '{' for sets/maps). The parser reports the position and what it found instead. parse() only accepts well-formed CQL collection literals or null.","triggerScenarios":"Calling codec.parse() (or session.prepare/execute paths that parse literals) with a string missing the opening bracket/brace — e.g. \"1,2,3\" instead of \"[1,2,3]\", or a quoted/mismatched delimiter like \"(1,2,3)\".","commonSituations":"Copying values out of cqlsh without delimiters; passing JSON arrays (\"[1,2]\" works but \"{\\\"a\\\":1}\" does not for a map); confusing set/map opening char '{' with list '[' after changing column type; empty-ish strings with stray whitespace then a wrong char.","solutions":["Pass a properly delimited CQL collection literal: list/set as [v1,v2] or {v1,v2}, map as {k1:v1,k2:v2}","Trim and validate the string starts with the codec's opening character before calling parse()","Bind typed Java collections instead of parsing strings (recommended): use setList/setSet/setMap or the codec's serialize path","If the input is JSON, convert it to a CQL literal first (e.g. build a List and let the codec format it with format())."],"exampleFix":"// before\nList<Integer> l = intListCodec.parse(\"1,2,3\"); // InvalidTypeException\n// after\nList<Integer> l = intListCodec.parse(\"[1,2,3]\");","handlingStrategy":"validation","validationCode":"// before parse\nString v = input == null ? null : input.trim();\nif (v == null || v.equalsIgnoreCase(\"null\")) return null;\nif (!(v.startsWith(\"[\") || v.startsWith(\"{\")))\n    throw new IllegalArgumentException(\"Expected CQL collection literal starting with '[' or '{': \" + input);","typeGuard":"static boolean isCollectionLiteral(String s) {\n    if (s == null) return false;\n    String t = s.trim();\n    return (t.startsWith(\"[\") && t.endsWith(\"]\")) || (t.startsWith(\"{\") && t.endsWith(\"}\"));\n}","tryCatchPattern":"try {\n    return codec.parse(literal);\n} catch (InvalidTypeException e) {\n    LOG.warn(\"Bad collection literal: {}\", e.getMessage());\n    return null;\n}","preventionTips":["Prefer binding typed Java collections over parsing string literals","When accepting user text, validate the leading '[' or '{' before parse()","Convert JSON input to Java collections first, then let format() produce the CQL literal"],"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"}