Skip to content

Fix ResultSetMetaData.getCatalogName throwing IndexOutOfBoundsException instead of SQLException for out-of-range columns#18242

Open
PDGGK wants to merge 1 commit into
apache:masterfrom
PDGGK:fix-getcatalogname-ioobe
Open

Fix ResultSetMetaData.getCatalogName throwing IndexOutOfBoundsException instead of SQLException for out-of-range columns#18242
PDGGK wants to merge 1 commit into
apache:masterfrom
PDGGK:fix-getcatalogname-ioobe

Conversation

@PDGGK

@PDGGK PDGGK commented Jul 18, 2026

Copy link
Copy Markdown
Contributor

Description

IoTDBResultMetadata.getCatalogName read columnInfoList.get(column - 1) before its range check, so an out-of-range column index threw a raw IndexOutOfBoundsException instead of the SQLException required by the ResultSetMetaData contract (the range check was therefore unreachable). This calls checkColumnIndex(column) first — as the seven sibling accessors in the class already do — and removes the now-redundant inline range check. checkColumnIndex is a strict superset of that check (it also rejects an empty column list) and throws a proper SQLException.

A test is added asserting that an out-of-range column throws SQLException rather than IndexOutOfBoundsException, and that a valid column is unaffected.

This closes #18241.

…ange column

IoTDBResultMetadata.getCatalogName read columnInfoList.get(column - 1) before its
range check, so column <= 0 or column > size threw a raw IndexOutOfBoundsException
instead of the SQLException the ResultSetMetaData contract requires (the range
check was therefore unreachable). Call checkColumnIndex(column) first, like the
sibling ResultSetMetaData accessors, and drop the now-redundant inline range
check. Add a test asserting an out-of-range column throws SQLException rather than
IndexOutOfBoundsException, and that a valid column is unaffected.

Signed-off-by: Zihan Dai <99155080+PDGGK@users.noreply.github.com>

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR fixes a JDBC ResultSetMetaData contract violation in IoTDBResultMetadata#getCatalogName(int) where an out-of-range column index could throw IndexOutOfBoundsException (due to columnInfoList.get(column - 1) being executed before validation) instead of the required SQLException. The change aligns getCatalogName with the existing validation pattern already used by sibling metadata accessors.

Changes:

  • Add an early checkColumnIndex(column) guard to IoTDBResultMetadata#getCatalogName and remove the now-unreachable inline range check.
  • Add a unit test asserting out-of-range indices throw SQLException (not IndexOutOfBoundsException) and that a valid index remains unaffected.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
iotdb-client/jdbc/src/main/java/org/apache/iotdb/jdbc/IoTDBResultMetadata.java Ensures getCatalogName validates column indices via checkColumnIndex before list access, returning SQLException for invalid indices.
iotdb-client/jdbc/src/test/java/org/apache/iotdb/jdbc/IoTDBResultMetadataTest.java Adds coverage for the out-of-range behavior and validates no regression for a valid column.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

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] ResultSetMetaData.getCatalogName throws IndexOutOfBoundsException instead of SQLException for out-of-range columns

2 participants