iotdb icon indicating copy to clipboard operation
iotdb copied to clipboard

Fix Java client time column access throwing ArrayIndexOutOfBoundsException (#17407)

Open PDGGK opened this issue 8 months ago • 2 comments

Description

Fixes #17407

This is the Java equivalent of the C++ client fix in #17400.

In IoTDBRpcDataSet.java, several ByTsBlockColumnIndex getter methods do not handle tsBlockColumnIndex < 0 (the time pseudo-column in tree model). Only getLongByTsBlockColumnIndex and getStringByTsBlockColumnIndex correctly handle this case. The remaining typed getters pass the negative index directly to TsBlock.getColumn(), causing ArrayIndexOutOfBoundsException.

Changes

Add tsBlockColumnIndex < 0 guards that throw StatementExecutionException with a clear message:

Method Guard added
getBooleanByTsBlockColumnIndex "Cannot read boolean from time column"
getDoubleByTsBlockColumnIndex "Cannot read double from time column"
getFloatByTsBlockColumnIndex "Cannot read float from time column"
getIntByTsBlockColumnIndex "Cannot read int32 from time column"
getBinaryTsBlockColumnIndex "Cannot read binary from time column"
getObjectByTsBlockIndex "Cannot read object from time column"

This is consistent with getLongByTsBlockColumnIndex which returns the time value for < 0, and getStringByTsBlockColumnIndex which returns the time value as a string. For non-compatible types, throwing a descriptive exception is preferred over an opaque ArrayIndexOutOfBoundsException.

PDGGK avatar Mar 31 '26 11:03 PDGGK

Hi, you can subscribe to the development mailing list and mention this PR there. This way, other developers can help you review the PR more quickly.

https://iotdb.apache.org/Community/Communication-Channels.html#_1-mailing-lists

HTHou avatar Apr 08 '26 07:04 HTHou

Thanks for the suggestion, @HTHou. Separately, I noticed CI was red and it was my change that caused it: making getObject reject the time pseudo-column was too aggressive. getObject on the time column is a valid, already-tested path (IoTDBJDBCResultSetTest#testQuery) and should keep returning the timestamp.

I've restored the time-column branch in the TIMESTAMP case of getObjectByTsBlockIndex and kept the new tsBlockColumnIndex < 0 guards only on the strictly-typed getters (boolean/int32/float/double/binary); getLong, getString and getObject continue to read the time column. IoTDBJDBCResultSetTest passes locally now.

PDGGK avatar Jun 25 '26 17:06 PDGGK