{"record":{"id":"3779f561c3d7759a","repo":"apache/cassandra","slug":"cannot-parse-map-value-from-s-at-character-d","errorCode":null,"errorMessage":"cannot parse map value from \"%s\", at character %d expecting '{' but got '%c'","messagePattern":"cannot parse map 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":2358,"sourceCode":"            if (value instanceof Map)\n            {\n                // runtime type ok, now check key and value types\n                Map<?, ?> map = (Map<?, ?>) value;\n                if (map.isEmpty()) return true;\n                Map.Entry<?, ?> entry = map.entrySet().iterator().next();\n                return keyCodec.accepts(entry.getKey()) && valueCodec.accepts(entry.getValue());\n            }\n            return false;\n        }\n\n        @Override\n        public Map<K, V> 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++) != '{')\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\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                {","sourceCodeStart":2340,"sourceCodeEnd":2376,"githubUrl":"https://github.com/apache/cassandra/blob/88fd0f6a0eaed8943f05ac9e8f947882b8ddc8f1/src/java/org/apache/cassandra/cql3/functions/types/TypeCodec.java#L2340-L2376","documentation":"Thrown by MapCodec.parse() when the CQL literal string does not start with '{' after leading whitespace. A map literal in CQL must begin with an opening brace; the parser reports the first offending character. This guarantees parse() only accepts syntactically valid map literals.","triggerScenarios":"Calling MapCodec.parse() with a string whose first non-space char is not '{', e.g. parse(\"<1='a'>\") (set/UDT style), parse(\"1:'a'\") (missing braces), or parsing a list literal \"[1,2]\" with the map codec.","commonSituations":"Passing a string produced for a different collection type (list/set literal) to the map codec; using Python/CLI repr instead of CQL literal syntax; off-by-one substring that dropped the leading brace.","solutions":["Ensure the string is a CQL map literal starting with '{' and ending with '}'","Check that you are using the correct codec (MapCodec vs ListCodec/SetCodec) for the value","Strip non-CQL decorations (quotes, type wrappers) before parsing"],"exampleFix":"// before\nmapCodec.parse(\"1:'a',2:'b'\");\n// after\nmapCodec.parse(\"{1:'a',2:'b'}\");","handlingStrategy":"validation","validationCode":"if (value == null || !value.trim().startsWith(\"{\"))\n    throw new IllegalArgumentException(\"Expected CQL map literal starting with '{': \" + value);\nmapCodec.parse(value);","typeGuard":"boolean looksLikeCqlMap(String s) {\n    return s != null && s.trim().startsWith(\"{\") && s.trim().endsWith(\"}\");\n}","tryCatchPattern":"try {\n    Map<K,V> m = mapCodec.parse(value);\n} catch (InvalidTypeException e) {\n    throw new IllegalArgumentException(\"Not a valid CQL map literal: \" + value, e);\n}","preventionTips":["Confirm the codec type matches the literal (map vs list vs set)","Strip language-specific repr (e.g. Python dict braces are the same, but '=' separators are not valid)","Regenerate literals with 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"}