You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
jdbc-v2: NullPointerException from prepareStatement when the JavaCC parser cannot parse an INSERT VALUES list #3013
With the default SQL parser (jdbc_sql_parser=JAVACC), Connection#prepareStatement throws a raw NullPointerException for an INSERT ... VALUES (...) statement whose values list the JavaCC grammar
cannot fully parse. The most common trigger is a heredoc string ($$...$$) — the grammar has no
heredoc token — but any token the grammar rejects inside the values list has the same effect.
Steps to reproduce
try (Connectionconn = DriverManager.getConnection("jdbc:ch:http://localhost:8123")) {
conn.prepareStatement("INSERT INTO t (s, n) VALUES ($$a@b$$, ?)");
}
java.lang.NullPointerException: Cannot invoke "java.lang.Integer.intValue()" because the return value of "java.util.Map.get(Object)" is null
at com.clickhouse.jdbc.internal.SqlParserFacade$JavaCCParser.parsePreparedStatement(SqlParserFacade.java:104)
at com.clickhouse.jdbc.ConnectionImpl.prepareStatement(...)
Other statements that reproduce it:
INSERT INTO t VALUES ($$?$$, ?)
INSERT INTO t VALUES (?, )
INSERT INTO t VALUES (@@, ?)
The server accepts the heredoc forms, e.g. INSERT INTO t (s, n) VALUES ($$a@b$$, 42) inserts the
string a@b, so this is purely client-side.
Expected behaviour
prepareStatement should not throw a NullPointerException. When the values list cannot be parsed,
the driver should fall back to its generic parameter-substitution path (which handles the statement
correctly) rather than fail.
Cause
dataClause() in jdbc-v2/src/main/javacc/ClickHouseSqlParser.jj records ValuesStart when it
matches the opening parenthesis and ValuesEnd when it matches the closing one. Its catch (ParseException) recovery skips to the end of the statement, so when the values list is
abandoned in between, ValuesStart is recorded but ValuesEnd is not. SqlParserFacade$JavaCCParser.parsePreparedStatement then unboxes the missing ValuesEnd position.
The ANTLR4 and ANTLR4_PARAMS_PARSER backends are not affected.
Activity
Fix jdbc-v2: NPE when the JavaCC parser cannot parse an INSERT VALUES…