{"record":{"id":"1bcddc93a98da582","repo":"apache/cassandra","slug":"failed-parsing-statement-s-reason-s-s","errorCode":null,"errorMessage":"Failed parsing statement: [%s] reason: %s %s","messagePattern":"Failed parsing statement: \\[(.+?)\\] reason: (.+?) (.+?)","errorType":"validation","errorClass":"SyntaxException","httpStatus":null,"severity":"error","filePath":"src/java/org/apache/cassandra/cql3/QueryProcessor.java","lineNumber":999,"sourceCode":"        catch (RequestValidationException e)\n        {\n            throw new IllegalArgumentException(e.getMessage(), e);\n        }\n    }\n    public static CQLStatement.Raw parseStatement(String queryStr) throws SyntaxException\n    {\n        try\n        {\n            return CQLFragmentParser.parseAnyUnhandled(CqlParser::query, queryStr);\n        }\n        catch (CassandraException ce)\n        {\n            throw ce;\n        }\n        catch (RuntimeException re)\n        {\n            logger.error(String.format(\"The statement: [%s] could not be parsed.\", queryStr), re);\n            throw new SyntaxException(String.format(\"Failed parsing statement: [%s] reason: %s %s\",\n                                                    queryStr,\n                                                    re.getClass().getSimpleName(),\n                                                    re.getMessage()));\n        }\n        catch (RecognitionException e)\n        {\n            throw new SyntaxException(\"Invalid or malformed CQL query string: \" + e.getMessage());\n        }\n    }\n\n    private static int measurePstmnt(Prepared value)\n    {\n        return Ints.checkedCast(ObjectSizes.measureDeep(value));\n    }\n\n    private static int getSizeOfPreparedStatementForCache(MD5Digest key, Prepared value)\n    {\n        if (value.pstmntSize < 0)","sourceCodeStart":981,"sourceCodeEnd":1017,"githubUrl":"https://github.com/apache/cassandra/blob/88fd0f6a0eaed8943f05ac9e8f947882b8ddc8f1/src/java/org/apache/cassandra/cql3/QueryProcessor.java#L981-L1017","documentation":"QueryProcessor.parseStatement catches RuntimeExceptions thrown while parsing/validating a CQL string and rethrows them as SyntaxException, logging the full stack trace at ERROR. It indicates the CQL text could not be turned into a statement object, though not by a grammar (RecognitionException) failure — usually a runtime error raised by post-parse semantic setup.","triggerScenarios":"Calling QueryProcessor.parseStatement (directly or via processQuery/prepare) with a CQL string whose parsing path throws a RuntimeException — e.g. invalid literals, unresolvable functions/aggregates triggered during statement construction, malformed collection literals.","commonSituations":"Queries built by string concatenation with malformed values; version skew where new CQL syntax is sent to an older server; bugs in custom or generated CQL; quoted identifiers or string escapes that break later validation.","solutions":["Fix the CQL statement syntax; check the server log for the full 'could not be parsed' stack trace to find the root RuntimeException","Validate/escape user input before interpolating it into CQL","Use bind markers instead of string-concatenating values","Confirm the syntax is supported by the server's Cassandra version"],"exampleFix":"// before\nString cql = \"SELECT * FROM t WHERE k IN (\" + ids.join(\")(\") + \")\"; // malformed\n// after\nString cql = \"SELECT * FROM t WHERE k IN (\" + ids.stream().map(i -> \"?\").collect(joining(\",\")) + \")\";","handlingStrategy":"try-catch","validationCode":"// basic sanity before sending\nif (cql == null || cql.trim().isEmpty()) throw new IllegalArgumentException(\"empty CQL\");","typeGuard":null,"tryCatchPattern":"try { session.execute(cql); } catch (SyntaxException e) { log.error(\"Bad CQL [{}]: {}\", cql, e.getMessage()); throw new IllegalArgumentException(\"malformed CQL\", e); }","preventionTips":["Use bind markers instead of string-concatenated values","Escape quotes/identifiers correctly","Test generated CQL in cqlsh before deploying","Check server log for the underlying RuntimeException stack trace"],"tags":["cql","parse-error","syntax"],"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"}