Skip to content

Fix findColumn NullPointerException for unknown column names (return SQLException)#18251

Open
PDGGK wants to merge 1 commit into
apache:masterfrom
PDGGK:fix-findcolumn-npe-sqlexception
Open

Fix findColumn NullPointerException for unknown column names (return SQLException)#18251
PDGGK wants to merge 1 commit into
apache:masterfrom
PDGGK:fix-findcolumn-npe-sqlexception

Conversation

@PDGGK

@PDGGK PDGGK commented Jul 20, 2026

Copy link
Copy Markdown
Contributor

Description

IoTDBRpcDataSet.findColumn(String) returned columnOrdinalMap.get(columnName) directly, so an unknown column name unboxed a null Integer into a NullPointerException instead of the SQLException that the ResultSet.findColumn contract requires. This guards the lookup and throws a checked StatementExecutionException (reusing the existing UNKNOWN_COLUMN_NAME message), mirroring the sibling findColumnNameByIndex. The JDBC boundary IoTDBJDBCResultSet.findColumn converts it to SQLException (like the existing getBigDecimal path), and SessionDataSet.DataIterator.findColumn propagates the checked exception, consistent with its sibling accessors. The identical NPE in the public IoTDBJDBCDataSet.findColumn is fixed the same way.

A test asserts that an unknown column name throws SQLException rather than NullPointerException, and that a valid column name still resolves.

This closes #18250.

findColumn returned columnOrdinalMap.get(columnName) directly, so an unknown
column name unboxed a null Integer into a NullPointerException instead of the
SQLException the JDBC contract (ResultSet.findColumn) requires. Guard the lookup
and throw StatementExecutionException (reusing the existing UNKNOWN_COLUMN_NAME
message), mirroring the sibling findColumnNameByIndex; the JDBC boundary
IoTDBJDBCResultSet.findColumn converts it to SQLException like the existing
getBigDecimal path, and SessionDataSet.DataIterator.findColumn propagates the
checked exception, consistent with its sibling accessors. Also fixes the
identical NPE in IoTDBJDBCDataSet.findColumn. Adds a test asserting an unknown
column throws SQLException rather than NPE.

Signed-off-by: Zihan Dai <99155080+PDGGK@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug] findColumn throws NullPointerException instead of SQLException for an unknown column name

1 participant