{"record":{"id":"b2de5a47561375cb","repo":"apache/cassandra","slug":"failed-parsing-s-s-reason-s-s","errorCode":null,"errorMessage":"Failed parsing %s: [%s] reason: %s %s","messagePattern":"Failed parsing (.+?): \\[(.+?)\\] reason: (.+?) (.+?)","errorType":"validation","errorClass":"SyntaxException","httpStatus":null,"severity":"error","filePath":"src/java/org/apache/cassandra/cql3/CQLFragmentParser.java","lineNumber":49,"sourceCode":" */\npublic final class CQLFragmentParser\n{\n\n    @FunctionalInterface\n    public interface CQLParserFunction<R>\n    {\n        R parse(CqlParser parser) throws RecognitionException;\n    }\n\n    public static <R> R parseAny(CQLParserFunction<R> parserFunction, String input, String meaning)\n    {\n        try\n        {\n            return parseAnyUnhandled(parserFunction, input);\n        }\n        catch (RuntimeException re)\n        {\n            throw new SyntaxException(String.format(\"Failed parsing %s: [%s] reason: %s %s\",\n                                                    meaning,\n                                                    input,\n                                                    re.getClass().getSimpleName(),\n                                                    re.getMessage()));\n        }\n        catch (RecognitionException e)\n        {\n            throw new SyntaxException(\"Invalid or malformed \" + meaning + \": \" + e.getMessage());\n        }\n    }\n\n    /**\n     * Just call a parser method in {@link CqlParser} - does not do any error handling.\n     */\n    public static <R> R parseAnyUnhandled(CQLParserFunction<R> parserFunction, String input) throws RecognitionException\n    {\n        // Lexer and parser\n        ErrorCollector errorCollector = new ErrorCollector(input);","sourceCodeStart":31,"sourceCodeEnd":67,"githubUrl":"https://github.com/apache/cassandra/blob/88fd0f6a0eaed8943f05ac9e8f947882b8ddc8f1/src/java/org/apache/cassandra/cql3/CQLFragmentParser.java#L31-L67","documentation":"CQL fragment parsing (types, identifiers, etc.) failed; the raw RecognitionException/RuntimeException is wrapped into a SyntaxException with the fragment text and the underlying exception class and message. It indicates the input string could not be parsed by the CQL grammar for the given meaning (e.g. a type literal).","triggerScenarios":"Calling CQLFragmentParser.parseAny (directly or via utilities like parseCQLLiteral/TypeParser) with a syntactically invalid string — e.g. a malformed collection literal `{'a'}` with wrong syntax, an invalid type string, or unbalanced brackets.","commonSituations":"Application code composing type strings or literals by hand; passing user input as CQL literals without escaping; version differences where newer literal syntax is sent to an older server.","solutions":["Inspect the embedded reason (%s %s fields) for the underlying RecognitionException message and fix the fragment syntax accordingly","Validate/escape user input before embedding it in CQL literals; prefer bound statements with typed values over string literals","Test the fragment in cqlsh to see the precise parse error","Upgrade the driver/server pair so both support the literal syntax in use"],"exampleFix":"// before\nString lit = \"{'a','b'\"; // unbalanced brace -> SyntaxException\n// after\nString lit = \"{'a','b'}\"; // or use a bound statement: stmt.setString(0, value)","handlingStrategy":"try-catch","validationCode":"// basic sanity before parsing a CQL fragment\nboolean looksBalanced(String fragment) {\n    int p=0,b=0,c=0;\n    for (char ch : fragment.toCharArray()) {\n        switch(ch){case '(':p++;break;case ')':p--;break;case '{':c++;break;case '}':c--;break;case '[':b++;break;case ']':b--;}\n    }\n    return p==0&&b==0&&c==0;\n}","typeGuard":null,"tryCatchPattern":"try { return CQLFragmentParser.parseAny(parserFn, input); }\ncatch (org.apache.cassandra.cql3.SyntaxException e) {\n    logger.warn(\"Invalid CQL fragment: {}\", input, e);\n    throw new IllegalArgumentException(\"Malformed CQL fragment: \" + input, e);\n}","preventionTips":["Prefer bound statements/typed values over hand-built CQL literals","Escape quotes and special characters in user-supplied fragments","Validate fragments in cqlsh or unit tests before deploying","Pin driver/server versions so literal syntax matches"],"tags":["cql","syntax","parser"],"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"}