Bug: Query parsing error handling problem: NPE when user types an incorrect query statement
Status: Open
Priority: Low
Created: 13/Sep/23 00:24

When using cassandra cqlsh shell (4.1.3 or 3.11.16), typing the following query will lead to an null pointer exception
{code:java}
cqlsh> CREATE KEYSPACE  ks WITH REPLICATION = { 'class' : 'SimpleStrategy', 'replication_factor' : 1 };
cqlsh> CREATE TABLE  ks.tb (c1 INT,c2 TEXT, PRIMARY KEY (c1));
cqlsh> INSERT INTO ks.tb (c1, c2) VALUES (0, 'v1');
cqlsh> UPDATE ks.tb SET c2 = 'v2' WHERE c1 = 0;
cqlsh> UPDATE ks.tb SET 9AMu = 2, c1 = 0,c2 = 'v2';
SyntaxException: Failed parsing statement: [UPDATE ks.tb SET 9AMu = 2, c1 = 0,c2 = 'v2';] reason: NullPointerException null {code}
Only typing the update query without creating ks can already trigger it.
{code:java}
cqlsh> UPDATE ks2.tb SET 9AMu = 2, c1 = 0,c2 = 'v2';
SyntaxException: Failed parsing statement: [UPDATE ks2.tb SET 9AMu = 2, c1 = 0,c2 = 'v2';] reason: NullPointerException null {code}
In system.log, it shows the following exception
{code:java}
ERROR [Native-Transport-Requests-1] 2023-09-13 00:17:01,463 QueryProcessor.java:891 - The statement: [UPDATE ks.tb SET 9AMu = 2, c1 = 0,c2 = 'v2';] could not be parsed.
java.lang.NullPointerException: null
        at org.apache.cassandra.cql3.Cql_Parser.addRawUpdate(Cql_Parser.java:396)
        at org.apache.cassandra.cql3.Cql_Parser.normalColumnOperation(Cql_Parser.java:14334)
        at org.apache.cassandra.cql3.Cql_Parser.columnOperationDifferentiator(Cql_Parser.java:14233)
        at org.apache.cassandra.cql3.Cql_Parser.columnOperation(Cql_Parser.java:14172)
        at org.apache.cassandra.cql3.Cql_Parser.updateStatement(Cql_Parser.java:3846)
        at org.apache.cassandra.cql3.Cql_Parser.cqlStatement(Cql_Parser.java:536)
        at org.apache.cassandra.cql3.CqlParser.cqlStatement(CqlParser.java:609)
        at org.apache.cassandra.cql3.CqlParser.query(CqlParser.java:363)
        at org.apache.cassandra.cql3.CQLFragmentParser.parseAnyUnhandled(CQLFragmentParser.java:76)
        at org.apache.cassandra.cql3.QueryProcessor.parseStatement(QueryProcessor.java:883)
        at org.apache.cassandra.cql3.QueryProcessor.getStatement(QueryProcessor.java:853)
        at org.apache.cassandra.cql3.QueryProcessor.parse(QueryProcessor.java:329)
        at org.apache.cassandra.transport.messages.QueryMessage.execute(QueryMessage.java:115)
        at org.apache.cassandra.transport.Message$Request.execute(Message.java:255)
        at org.apache.cassandra.transport.Dispatcher.processRequest(Dispatcher.java:166)
        at org.apache.cassandra.transport.Dispatcher.processRequest(Dispatcher.java:185)
        at org.apache.cassandra.transport.Dispatcher.processRequest(Dispatcher.java:212)
        at org.apache.cassandra.transport.Dispatcher$RequestProcessor.run(Dispatcher.java:109)
        at org.apache.cassandra.concurrent.FutureTask$1.call(FutureTask.java:96)
        at org.apache.cassandra.concurrent.FutureTask.call(FutureTask.java:61)
        at org.apache.cassandra.concurrent.FutureTask.run(FutureTask.java:71)
        at org.apache.cassandra.concurrent.SEPWorker.run(SEPWorker.java:142)
        at io.netty.util.concurrent.FastThreadLocalRunnable.run(FastThreadLocalRunnable.java:30)
        at java.lang.Thread.run(Thread.java:750) {code}
 

The incorrect user input should be captured inside the system (invisible to users) and only return the SyntaxException. (I have attached the system.log.)