{"record":{"id":"ca59bc5acdb93896","repo":"apache/cassandra","slug":"malformed-map-value-s-missing-closing","errorCode":null,"errorMessage":"Malformed map value \"%s\", missing closing '}'","messagePattern":"Malformed map value \"(.+?)\", missing closing '\\}'","errorType":"exception","errorClass":"InvalidTypeException","httpStatus":null,"severity":"error","filePath":"src/java/org/apache/cassandra/cql3/functions/types/TypeCodec.java","lineNumber":2423,"sourceCode":"                    e);\n                }\n\n                V v = valueCodec.parse(value.substring(idx, n));\n                idx = n;\n\n                m.put(k, v);\n\n                idx = ParseUtils.skipSpaces(value, idx);\n                if (value.charAt(idx) == '}') return m;\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            throw new InvalidTypeException(\n            String.format(\"Malformed map value \\\"%s\\\", missing closing '}'\", value));\n        }\n\n        @Override\n        public String format(Map<K, V> value)\n        {\n            if (value == null) return \"NULL\";\n            StringBuilder sb = new StringBuilder();\n            sb.append('{');\n            int i = 0;\n            for (Map.Entry<K, V> e : value.entrySet())\n            {\n                if (i++ != 0) sb.append(',');\n                sb.append(keyCodec.format(e.getKey()));\n                sb.append(':');\n                sb.append(valueCodec.format(e.getValue()));\n            }\n            sb.append('}');","sourceCodeStart":2405,"sourceCodeEnd":2441,"githubUrl":"https://github.com/apache/cassandra/blob/88fd0f6a0eaed8943f05ac9e8f947882b8ddc8f1/src/java/org/apache/cassandra/cql3/functions/types/TypeCodec.java#L2405-L2441","documentation":"Thrown by MapCodec.parse() when the literal string ends after parsing at least one entry but the closing '}' was never found — unbalanced braces. Like the collection equivalent, the value is truncated and cannot be a valid CQL map literal.","triggerScenarios":"Calling MapCodec.parse() with a truncated map literal like \"{1:'a',2:'b'\" — all entries parse but end-of-string is reached without '}'.","commonSituations":"Substring/log-truncation cutting off the final brace; user input missing the closing brace; quoted value tokens swallowing the closing brace due to unescaped quotes.","solutions":["Append the missing '}' to complete the map literal","Fix element quoting so the closing brace is not consumed inside a quoted token","Pre-validate brace balance before calling parse()","Use codec.format() to produce well-formed literals"],"exampleFix":"// before\nmapCodec.parse(\"{1:'a',2:'b'\");\n// after\nmapCodec.parse(\"{1:'a',2:'b'}\");","handlingStrategy":"validation","validationCode":"String t = value == null ? null : value.trim();\nif (t == null || !t.startsWith(\"{\") || !t.endsWith(\"}\"))\n    throw new IllegalArgumentException(\"Unbalanced map literal: \" + value);\nmapCodec.parse(value);","typeGuard":"boolean isClosedMap(String s) {\n    String t = s == null ? \"\" : s.trim();\n    int depth = 0; boolean q = false;\n    for (char c : t.toCharArray()) {\n        if (c == '\\'') q = !q;\n        else if (!q) { if (c == '{') depth++; if (c == '}') depth--; }\n    }\n    return depth == 0 && !q;\n}","tryCatchPattern":"try {\n    Map<K,V> m = mapCodec.parse(value);\n} catch (InvalidTypeException e) {\n    if (e.getMessage().contains(\"missing closing\"))\n        value = value + \"}\"; // attempt repair, then re-validate\n    throw e;\n}","preventionTips":["Verify braces balance before parsing hand-built literals","Beware log truncation of literals before parse","Escape quotes so '}' isn't swallowed by a quoted token"],"tags":["cql","parsing","map","codec","invalid-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"}