{"record":{"id":"7aa7d617a649fce6","repo":"apache/cassandra","slug":"cannot-parse-map-value-from-s-invalid-cql-valu","errorCode":null,"errorMessage":"Cannot parse map value from \"%s\", invalid CQL value at character %d","messagePattern":"Cannot parse map 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":2377,"sourceCode":"                String.format(\n                \"cannot parse map value from \\\"%s\\\", at character %d expecting '{' but got '%c'\",\n                value, idx, value.charAt(idx)));\n\n            idx = ParseUtils.skipSpaces(value, idx);\n\n            if (value.charAt(idx) == '}') return newInstance(0);\n\n            Map<K, V> m = new HashMap<>();\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 map value from \\\"%s\\\", invalid CQL value at character %d\",\n                    value, idx),\n                    e);\n                }\n\n                K k = keyCodec.parse(value.substring(idx, n));\n                idx = n;\n\n                idx = ParseUtils.skipSpaces(value, idx);\n                if (value.charAt(idx++) != ':')\n                    throw new InvalidTypeException(\n                    String.format(\n                    \"Cannot parse map value from \\\"%s\\\", at character %d expecting ':' but got '%c'\",\n                    value, idx, value.charAt(idx)));\n                idx = ParseUtils.skipSpaces(value, idx);\n\n                try","sourceCodeStart":2359,"sourceCodeEnd":2395,"githubUrl":"https://github.com/apache/cassandra/blob/88fd0f6a0eaed8943f05ac9e8f947882b8ddc8f1/src/java/org/apache/cassandra/cql3/functions/types/TypeCodec.java#L2359-L2395","documentation":"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.","triggerScenarios":"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'}\".","commonSituations":"User-supplied map literals pasted from logs with dropped characters; unquoted keys containing CQL delimiters (',', ':', '}'); programmatic string building that forgot to quote string keys.","solutions":["Quote string keys with single quotes (and double any embedded quotes) in the literal","Remove stray delimiter characters or fix truncation around the reported index","Use codec.format(map) to generate the literal instead of concatenating strings"],"exampleFix":"// before\nmapCodec.parse(\"{unterminated:'v'}\");\n// after\nmapCodec.parse(\"{'unterminated':'v'}\");","handlingStrategy":"validation","validationCode":"// quote string keys before parsing\nString safe = keys.stream()\n    .map(k -> k instanceof String ? \"'\" + ((String) k).replace(\"'\", \"''\") + \"'\" : k.toString())\n    .collect(Collectors.joining(\",\", \"{\", \"}\"));\nmapCodec.parse(safe);","typeGuard":null,"tryCatchPattern":"try {\n    Map<K,V> m = mapCodec.parse(value);\n} catch (InvalidTypeException e) {\n    int idx = parseIdx(e.getMessage());\n    throw new IllegalArgumentException(\"Bad token at char \" + idx + \" in: \" + value, e);\n}","preventionTips":["Always quote string keys with single quotes in CQL literals","Double any embedded single quotes ('')","Avoid hand-built literals; use codec.format()"],"tags":["cql","parsing","map","codec"],"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"}