Repository navigation
Description
Description
In jdbc-v2, Connection.createArrayOf(typeName, ...) and Connection.createStruct(typeName, ...) throw an unchecked IllegalArgumentException (or NumberFormatException) when the type-name parser rejects typeName. Both methods declare throws SQLException. A caller that catches SQLException does not catch this error. Frameworks that translate SQLException (for example Spring's SQLExceptionTranslator) also do not see it.
All type names that the parser rejects are affected (see the results below). The server also rejects these names, so an exception is correct. Only the exception type is wrong. The other failures of the two methods (for example a closed connection, or a non-Tuple type in createStruct) already give SQLException.
Steps to reproduce
- Connect with jdbc-v2.
- Call
conn.createArrayOf("NoSuchType", new Object[] {1})intry { ... } catch (SQLException e) { ... }. - The
catchblock does not run.java.lang.IllegalArgumentException: Unknown data type: NoSuchTypegoes out of thetry.createStruct("Tuple(NoSuchType, UInt8)", ...)gives the same result.
Error Log or Exception StackTrace
java.lang.IllegalArgumentException: Unknown data type: NoSuchType
at com.clickhouse.data.ClickHouseDataType.of(ClickHouseDataType.java:497)
at com.clickhouse.data.ClickHouseColumn.readColumn(ClickHouseColumn.java:714)
at com.clickhouse.data.ClickHouseColumn.of(ClickHouseColumn.java:763)
at com.clickhouse.jdbc.ConnectionImpl.createArrayOf(ConnectionImpl.java:652)
java.lang.IllegalArgumentException: Unknown data type: NoSuchType
at com.clickhouse.data.ClickHouseDataType.of(ClickHouseDataType.java:497)
at com.clickhouse.data.ClickHouseColumn.readColumn(ClickHouseColumn.java:714)
at com.clickhouse.data.ClickHouseColumn.readColumn(ClickHouseColumn.java:544)
at com.clickhouse.data.ClickHouseColumn.of(ClickHouseColumn.java:763)
at com.clickhouse.jdbc.ConnectionImpl.createStruct(ConnectionImpl.java:667)
Results of the jdbc-v2 calls (same program, same connection):
createArrayOf("Int32") -> OK
createArrayOf("NoSuchType") -> java.lang.IllegalArgumentException: Unknown data type: NoSuchType
createArrayOf("Array(NoSuchType)") -> java.lang.IllegalArgumentException: Unknown data type: NoSuchType
createArrayOf("Nullable(Strng)") -> java.lang.IllegalArgumentException: Unknown data type: Strng
createArrayOf("Array(Int32") -> java.lang.IllegalArgumentException: Missing ')' for '(' at position 5
createArrayOf("Decimal(abc, 2)") -> java.lang.NumberFormatException: For input string: "abc"
createArrayOf("") -> java.lang.IllegalArgumentException: Non-empty typeName is required
createStruct("Tuple(Int8, String)") -> OK
createStruct("Int32") -> java.sql.SQLException (HY000): Only Tuple datatype is supported for Struct
createStruct("NoSuchType") -> java.lang.IllegalArgumentException: Unknown data type: NoSuchType
createStruct("Tuple(NoSuchType, UInt8)") -> java.lang.IllegalArgumentException: Unknown data type: NoSuchType
createStruct("Tuple(Int8, String") -> java.lang.IllegalArgumentException: Missing ')' for '(' at position 5
createStruct("Tuple(Decimal(abc, 2), UInt8)") -> java.lang.NumberFormatException: For input string: "abc"
createStruct("") -> java.lang.IllegalArgumentException: Non-empty typeName is required
createArrayOf(null) / createStruct(null) -> java.sql.SQLFeatureNotSupportedException: typeName cannot be null
closed connection, both methods -> java.sql.SQLException (08000): Connection is closed
The server rejects the same type names (SELECT toTypeName(defaultValueOfTypeName('<type>'))):
NoSuchType Code: 50. DB::Exception: Unknown data type family: NoSuchType ... (UNKNOWN_TYPE)
Nullable(Strng) Code: 50. DB::Exception: Unknown data type family: Strng. Maybe you meant: ['String'] ... (UNKNOWN_TYPE)
Tuple(NoSuchType, UInt8) Code: 50. DB::Exception: Unknown data type family: NoSuchType ... (UNKNOWN_TYPE)
Array(Int32 Code: 62. DB::Exception: Syntax error (data type): ... Unmatched parentheses: '(' at position 6 is never closed ...
Decimal(abc, 2) Code: 43. DB::Exception: Decimal argument precision is invalid ... (ILLEGAL_TYPE_OF_ARGUMENT)
Expected Behaviour
Both methods throw java.sql.SQLException for a type name that they cannot parse, with the parser exception as the cause. The SQLState is HY000, as for the other client-side errors in these methods.
java.sql.Connection Javadoc:
createArrayOf: "SQLException - if a database error occurs, the JDBC type is not appropriate for the typeName and the conversion is not supported, the typeName is null or this method is called on a closed connection"createStruct: "SQLException - if a database error occurs, typeName is null or this method is called on a closed connection"
Root cause
In jdbc-v2/src/main/java/com/clickhouse/jdbc/ConnectionImpl.java:
createArrayOfcallsClickHouseColumn.of("array", typeName)at line 652, before itstry { ... } catch (Exception e) { throw new SQLException("Failed to create array", ...) }block. So a parse exception is not wrapped.createStructcallsClickHouseColumn.of("v", typeName)at line 667 with notry/catch.
The fix is a try/catch around the parse in each method. A caller that catches IllegalArgumentException from these methods then gets SQLException, which both signatures already declare.
Polyglot AI can open a fix PR if a maintainer assigns this issue to @polyglotAI-bot.
Related: #3344 is a different parse failure (Enum elements without numbers). After a fix for #3344, createArrayOf("NoSuchType", ...) still throws IllegalArgumentException.
Code Example
Properties props = new Properties();
props.setProperty("user", "default");
props.setProperty("password", "<password>");
try (Connection conn = DriverManager.getConnection("jdbc:clickhouse://<host>:8123/default", props)) {
try {
conn.createArrayOf("NoSuchType", new Object[] {1});
// same for: conn.createStruct("Tuple(NoSuchType, UInt8)", new Object[] {1, 2});
} catch (SQLException e) {
System.out.println("caught: " + e); // not reached
}
}
// Exception in thread "main" java.lang.IllegalArgumentException: Unknown data type: NoSuchTypeConfiguration
Client Configuration
// default jdbc-v2 configuration, no extra propertiesEnvironment
- Cloud
- Client version: jdbc-v2
0.12.0-rc1-SNAPSHOT(main, f73e372) - Language version: OpenJDK 17.0.21
- OS: Linux (Docker)
ClickHouse Server
- ClickHouse Server version: 26.9.1.1629
- ClickHouse Server non-default settings, if any: none
CREATE TABLEstatements for tables involved: none- Sample data for all these tables: none
Found by automated analysis (Polyglot AI) while working on #3344. Verified against a live server. Shortened on 2026-11-20: the edit history has the first version.
Activity