apache/cassandra · error · InvalidTypeException
Malformed map value "%s", missing closing '}'
Error message
Malformed map value "%s", missing closing '}'
What it means
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.
Source
Thrown at src/java/org/apache/cassandra/cql3/functions/types/TypeCodec.java:2423
e);
}
V v = valueCodec.parse(value.substring(idx, n));
idx = n;
m.put(k, v);
idx = ParseUtils.skipSpaces(value, idx);
if (value.charAt(idx) == '}') return m;
if (value.charAt(idx++) != ',')
throw new InvalidTypeException(
String.format(
"Cannot parse map value from \"%s\", at character %d expecting ',' but got '%c'",
value, idx, value.charAt(idx)));
idx = ParseUtils.skipSpaces(value, idx);
}
throw new InvalidTypeException(
String.format("Malformed map value \"%s\", missing closing '}'", value));
}
@Override
public String format(Map<K, V> value)
{
if (value == null) return "NULL";
StringBuilder sb = new StringBuilder();
sb.append('{');
int i = 0;
for (Map.Entry<K, V> e : value.entrySet())
{
if (i++ != 0) sb.append(',');
sb.append(keyCodec.format(e.getKey()));
sb.append(':');
sb.append(valueCodec.format(e.getValue()));
}
sb.append('}');View on GitHub (pinned to 88fd0f6a0e)
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
Example fix
// before
mapCodec.parse("{1:'a',2:'b'");
// after
mapCodec.parse("{1:'a',2:'b'}"); Defensive patterns
Strategy: validation
Validate before calling
String t = value == null ? null : value.trim();
if (t == null || !t.startsWith("{") || !t.endsWith("}"))
throw new IllegalArgumentException("Unbalanced map literal: " + value);
mapCodec.parse(value); Type guard
boolean isClosedMap(String s) {
String t = s == null ? "" : s.trim();
int depth = 0; boolean q = false;
for (char c : t.toCharArray()) {
if (c == '\'') q = !q;
else if (!q) { if (c == '{') depth++; if (c == '}') depth--; }
}
return depth == 0 && !q;
} Try / catch
try {
Map<K,V> m = mapCodec.parse(value);
} catch (InvalidTypeException e) {
if (e.getMessage().contains("missing closing"))
value = value + "}"; // attempt repair, then re-validate
throw e;
} Prevention
- 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
When it happens
Trigger: Calling MapCodec.parse() with a truncated map literal like "{1:'a',2:'b'" — all entries parse but end-of-string is reached without '}'.
Common situations: 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.
Understand the failure class
Background: "Invalid ... format", "must be in format X", "does not look like a ..." — invalid argument format errors across CLI tools and libraries — this error's family across 17 libraries.
- Parsing and encoding errors: unexpected token, malformed input — why parsers reject input and how to find the real culprit.
Related errors
- Malformed collection value "%s", missing closing '%s'
- cannot parse map value from "%s", at character %d expecting
- Cannot parse map value from "%s", invalid CQL value at chara
- Cannot parse map value from "%s", at character %d expecting
- Cannot parse map value from "%s", at character %d expecting
AI-assisted analysis of apache/cassandra@88fd0f6a0e (2026-09-10).
Data as JSON: /api/errors/ca59bc5acdb93896.
Report an issue: GitHub.