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
clickhouse-jdbc (v1): NullPointerException from prepareStatement when the JavaCC parser cannot parse an INSERT VALUES list #3033
Connection#prepareStatement throws a raw NullPointerException in the legacy clickhouse-jdbc (v1)
driver 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.
This is the same defect as #3013, in the v1 module's own copy of the grammar and its own consumer.
Steps to reproduce
System.setProperty("clickhouse.jdbc.v1", "true");
try (Connectionconn = DriverManager.getConnection("jdbc:ch:http://localhost:8123")) {
conn.prepareStatement("insert into t 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.ClickHouseConnectionImpl.prepareStatement(ClickHouseConnectionImpl.java:826)
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.
Cause
dataClause() in clickhouse-jdbc/src/main/javacc/ClickHouseSqlParser.jj records ValuesStart at
the opening parenthesis and ValuesEnd at the closing one. Its catch (ParseException e) recovery
block skips ahead to the next ;/EOF without discarding the half-recorded pair, so the statement is
left with ValuesStart but no ValuesEnd (or, for a multi-group values list, ValuesEnd but no ValuesStart). ClickHouseConnectionImpl then unboxes ValuesEnd unguarded inside a ValuesStart != null branch.
Environment
Client version: 0.11.0-rc1 (main)
Language version: Java 17
Server version: 26.x (any; the failure is client-side, before any request is sent)
Activity
Fix clickhouse-jdbc: NPE when the JavaCC parser cannot parse an INSER…