{"record":{"id":"ea7f14c2aec36a31","repo":"apache/cassandra","slug":"syntax-error-parsing-s-at-char-d-s","errorCode":null,"errorMessage":"Syntax error parsing '%s' at char %d: %s","messagePattern":"Syntax error parsing '(.+?)' at char (.+?): (.+?)","errorType":"validation","errorClass":"SyntaxException","httpStatus":null,"severity":"error","filePath":"src/java/org/apache/cassandra/db/marshal/TypeParser.java","lineNumber":539,"sourceCode":"        {\n            Method method = typeClass.getDeclaredMethod(\"getInstance\", TypeParser.class);\n            return (AbstractType<?>) method.invoke(null, parser);\n        }\n        catch (NoSuchMethodException | IllegalAccessException e)\n        {\n            throw new ConfigurationException(\"Invalid comparator class \" + typeClass.getName() + \": must define a public static instance field or a public static method getInstance(TypeParser).\");\n        }\n        catch (InvocationTargetException e)\n        {\n            ConfigurationException ex = new ConfigurationException(\"Invalid definition for comparator \" + typeClass.getName() + \".\");\n            ex.initCause(e.getTargetException());\n            throw ex;\n        }\n    }\n\n    private void throwSyntaxError(String msg) throws SyntaxException\n    {\n        throw new SyntaxException(String.format(\"Syntax error parsing '%s' at char %d: %s\", str, idx, msg));\n    }\n\n    private boolean isEOS()\n    {\n        return isEOS(str, idx);\n    }\n\n    private static boolean isEOS(String str, int i)\n    {\n        return i >= str.length();\n    }\n\n    private static boolean isBlank(int c)\n    {\n        return c == ' ' || c == '\\t' || c == '\\n';\n    }\n\n    private void skipBlank()","sourceCodeStart":521,"sourceCodeEnd":557,"githubUrl":"https://github.com/apache/cassandra/blob/88fd0f6a0eaed8943f05ac9e8f947882b8ddc8f1/src/java/org/apache/cassandra/db/marshal/TypeParser.java#L521-L557","documentation":"TypeParser.throwSyntaxError is the shared helper that raises a SyntaxException carrying the full input string, current character index, and a specific reason (unexpected character, bad alias, invalid hex, expecting ':' or '=>' token, etc.). It is the canonical 'malformed type string' error in Cassandra's type parser.","triggerScenarios":"Any of getKeyValueParameters, getAliasParameters, getCollectionsParameters, fromHex, or getUserTypeParameters encountering an unexpected token: e.g. DynamicCompositeType(a!UTF8Type) (unexpected character '!'), an alias longer than one char, invalid hex bytes, or a missing ':' between a field name and type in a UTD/collections parameter list.","commonSituations":"Hand-written comparator strings with typos, using '=' instead of '=>' in DynamicCompositeType aliases, odd-length or non-hex key strings, missing colons in UserType field definitions, copy-pasted type strings with smart quotes or stray whitespace characters.","solutions":["Read the reason suffix after 'at char N:' in the message — it names the exact problem (unexpected character, expecting ':' token, bad alias, hex error)","Go to that character index in the string and fix the token: use '=>' for aliases, ':' for field separators, valid even-length hex for keys","Validate the whole type string with AbstractType.parse() in a scratch environment before applying schema changes","Regenerate complex type strings programmatically (e.g. via stringifyTKeyValueParameters) instead of concatenating them by hand"],"exampleFix":"// before\nTypeParser.parse(\"DynamicCompositeType(a = UTF8Type)\"); // '=>' expected\n// after\nTypeParser.parse(\"DynamicCompositeType(a => UTF8Type)\");","handlingStrategy":"try-catch","validationCode":"static void preflightTypeString(String s) {\n    if (s == null || s.isEmpty()) return;\n    int depth = 0;\n    for (char c : s.toCharArray()) {\n        if (c == '(') depth++;\n        else if (c == ')') depth--;\n        if (depth < 0) throw new IllegalArgumentException(\"Unbalanced ')'\");\n    }\n    if (depth != 0) throw new IllegalArgumentException(\"Unclosed '('\");\n}","typeGuard":null,"tryCatchPattern":"try {\n    AbstractType<?> t = TypeParser.parse(typeString);\n} catch (SyntaxException e) {\n    // message format: Syntax error parsing '<str>' at char <idx>: <reason>\n    int idx = Integer.parseInt(e.getMessage().replaceAll(\".*at char (\\\\d+):.*\", \"$1\"));\n    throw new SchemaConfigurationException(\"Bad token in type string near index \" + idx + \": \" + e.getMessage(), e);\n}","preventionTips":["Parse the reason after 'at char N:' in the message to pinpoint the bad token","Use the documented token syntax: '=>' for aliases, ':' for field separators, valid even-length hex keys","Build complex type strings via helpers (stringifyTKeyValueParameters) rather than hand concatenation","Avoid smart quotes and invisible characters when copying type strings from docs or chats"],"tags":["cassandra","type-parser","syntax-exception","malformed-type-string"],"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-17T15:17:12.973Z"}