Fix ResultSetMetaData.getCatalogName throwing IndexOutOfBoundsException instead of SQLException for out-of-range columns#18242
Open
PDGGK wants to merge 1 commit into
Open
Conversation
…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>
Contributor
There was a problem hiding this comment.
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 toIoTDBResultMetadata#getCatalogNameand remove the now-unreachable inline range check. - Add a unit test asserting out-of-range indices throw
SQLException(notIndexOutOfBoundsException) 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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
IoTDBResultMetadata.getCatalogNamereadcolumnInfoList.get(column - 1)before its range check, so an out-of-range column index threw a rawIndexOutOfBoundsExceptioninstead of theSQLExceptionrequired by theResultSetMetaDatacontract (the range check was therefore unreachable). This callscheckColumnIndex(column)first — as the seven sibling accessors in the class already do — and removes the now-redundant inline range check.checkColumnIndexis a strict superset of that check (it also rejects an empty column list) and throws a properSQLException.A test is added asserting that an out-of-range column throws
SQLExceptionrather thanIndexOutOfBoundsException, and that a valid column is unaffected.This closes #18241.