{"record":{"id":"b2967c54fab4d6e3","repo":"apache/cassandra","slug":"invalid-or-malformed","errorCode":null,"errorMessage":"Invalid or malformed ","messagePattern":"Invalid or malformed ","errorType":"validation","errorClass":"SyntaxException","httpStatus":null,"severity":"error","filePath":"src/java/org/apache/cassandra/cql3/CQLFragmentParser.java","lineNumber":57,"sourceCode":"    }\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);\n        CharStream stream = new ANTLRStringStream(input);\n        CqlLexer lexer = new CqlLexer(stream);\n        lexer.addErrorListener(errorCollector);\n\n        TokenStream tokenStream = new CommonTokenStream(lexer);\n        CqlParser parser = new CqlParser(tokenStream);\n        parser.addErrorListener(errorCollector);\n","sourceCodeStart":39,"sourceCodeEnd":75,"githubUrl":"https://github.com/apache/cassandra/blob/88fd0f6a0eaed8943f05ac9e8f947882b8ddc8f1/src/java/org/apache/cassandra/cql3/CQLFragmentParser.java#L39-L75","documentation":"Cassandra throws this SyntaxException from CQLFragmentParser.parseAny when the ANTLR lexer/parser raises a RecognitionException while parsing a CQL fragment. The message is generic ('Invalid or malformed <meaning>') plus the raw parser message, meaning the submitted CQL text could not be tokenized or parsed according to the grammar. It is a client-facing indication of syntactically invalid CQL.","triggerScenarios":"Calling any CQL parsing entry point (e.g. QueryProcessor.parseStatement, CQLFragmentParser.parseAny) with malformed CQL: unbalanced quotes/parentheses, unknown keywords, or a grammar-level error that is not recovered as a detailed ErrorCollector message.","commonSituations":"Hand-built queries with unescaped string literals or semicolons; programmatically generated CQL with missing clauses; driver-side string concatenation injecting user input; pasting CQL from another dialect (MySQL/Postgres syntax).","solutions":["Run the failing CQL string through cqlsh to see the full parser error message","Check for unescaped quotes, missing commas, or stray semicolons in the CQL text","Validate generated queries against the CQL grammar for your Cassandra version before executing","Escape identifiers with double quotes and literals with single quotes correctly"],"exampleFix":"// before\nString cql = \"SELECT * FROM users WHERE name = 'O'Brien'\";\n// after\nString cql = \"SELECT * FROM users WHERE name = 'O''Brien'\";","handlingStrategy":"validation","validationCode":"private static boolean isPlausibleCql(String cql) { return cql != null && !cql.trim().isEmpty() && countOccurrences(cql, '\\'') % 2 == 0; }","typeGuard":null,"tryCatchPattern":"try { session.execute(cql); } catch (com.datastax.driver.core.exceptions.SyntaxException e) { log.error(\"Bad CQL: {}\", cql, e); }","preventionTips":["Escape single quotes in literals by doubling them","Use prepared statements instead of string concatenation","Lint CQL with cqlsh before embedding in code","Keep identifiers quoted when they contain special characters"],"tags":["cql","syntax","parsing"],"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-14T11:17:12.474Z"}