apache/cassandra · error · SyntaxException
Syntax error parsing
Error message
Syntax error parsing '%s' at char %d: unexpected end of string
What it means
TypeParser.getKeyValueParameters() parses a parenthesized key=value parameter list (used by types like DynamicCompositeType). This SyntaxException is thrown when the string ends before the closing ')' is found — the parameter list was opened with '(' but never properly closed.
Solutions
- Balance the parentheses in the type string: every '(' needs a matching ')', e.g. DynamicCompositeType(a=BytesType, b=UTF8Type)
- Check the char index in the message to see where the parser ran off the end; look for truncation or a swallowed closing paren there
- If the string comes from stored schema metadata, fix it via ALTER TABLE or schema repair before restarting nodes
- Validate the type string with AbstractType.parse() in a test or cqlsh before applying it to production schema
Example fix
// before
AbstractType.parse("DynamicCompositeType(a = UTF8Type");
// after
AbstractType.parse("DynamicCompositeType(a = UTF8Type)"); Defensive patterns
Strategy: try-catch
Validate before calling
static void validateTypeString(String s) {
long open = s.chars().filter(c -> c == '(').count();
long close = s.chars().filter(c -> c == ')').count();
if (open != close || s.trim().endsWith("("))
throw new IllegalArgumentException("Unbalanced parentheses in type string: " + s);
} Type guard
static boolean isBalanced(String s) {
int depth = 0;
for (char c : s.toCharArray()) {
if (c == '(') depth++;
else if (c == ')') depth--;
if (depth < 0) return false;
}
return depth == 0;
} Try / catch
try {
AbstractType<?> type = TypeParser.parse(typeString);
} catch (SyntaxException e) {
logger.error("Invalid type string, check parentheses: {}", e.getMessage());
throw new SchemaConfigurationException("Malformed type definition", e);
} Prevention
- Always balance parentheses — count '(' vs ')' before submitting schema changes
- Build parameterized type strings with helper methods like stringifyTKeyValueParameters instead of manual concatenation
- Test type strings with AbstractType.parse() in a unit test before applying them to a cluster
When it happens
Trigger: Calling getKeyValueParameters() on a TypeParser whose string has '(' but the loop exits via skipBlankAndComma() returning false because the parser reached end-of-string before seeing ')', e.g. TypeParser.parse("DynamicCompositeType(a=BytesType") or "DynamicCompositeType(a=BytesType, ".
Common situations: Typos in comparator strings in schema definitions (cqlsh CREATE TABLE ... WITH comparator options), hand-edited cassandra-cli comparator metadata, migration scripts carrying truncated type strings, or programmatic AbstractType.parse() calls with unbalanced parentheses.
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.
Related errors
- Syntax error parsing
- FrozenType() only accepts one parameter
- Invalid comparator class
- MapType takes exactly 2 type parameters
- ReversedType takes exactly one argument, " + types.size() +…
AI-assisted analysis of apache/cassandra@88fd0f6a0e (2026-09-10).
Data as JSON: /api/errors/95a9c0b3062568ed.
Report an issue: GitHub.
Appendix: source
Thrown at src/java/org/apache/cassandra/db/marshal/TypeParser.java:238
return map;
}
String k = readNextIdentifier();
String v = "";
skipBlank();
if (str.charAt(idx) == '=')
{
++idx;
skipBlank();
v = readNextIdentifier();
}
else if (str.charAt(idx) != ',' && str.charAt(idx) != ')')
{
throwSyntaxError("unexpected character '" + str.charAt(idx) + "'");
}
map.put(k, v);
}
throw new SyntaxException(String.format("Syntax error parsing '%s' at char %d: unexpected end of string", str, idx));
}
public static String stringifyVectorParameters(AbstractType<?> type, boolean ignoreFreezing, int dimension)
{
return "(" + type.toString(ignoreFreezing) + " , " + dimension + ")";
}
public Vector getVectorParameters()
{
if (isEOS())
return null;
if (str.charAt(idx) != '(')
throw new IllegalStateException();
++idx; // skipping '('
AbstractType<?> type = parse();
if (!skipBlankAndComma())
throw new IllegalStateException();View on GitHub (pinned to 88fd0f6a0e)