Skip to content

[Fix][#18160] Prevent NPE in SessionConnection when query response is null - #18903

Open
AdamsF-creator wants to merge 1 commit into
apache:masterfrom
AdamsF-creator:fix-session-export-npe
Open

AdamsF-creator wants to merge 1 commit into
apache:masterfrom
AdamsF-creator:fix-session-export-npe

Conversation

@AdamsF-creator

Copy link
Copy Markdown
Contributor

Description

Fixes #18160

Content1: Background & Problem

When executing queries via SessionConnection, if the RPC layer or network retry fails to obtain a valid response from the server, result.getResult() can be null. The client previously invoked execResp.getStatus() directly without verifying if execResp was null, leading to an unexpected NullPointerException (NPE) rather than a descriptive connection exception.

Content2: Defensive Null Check & Exception Handling

Added defensive null-checks for execResp / tsExecuteStatementResp across all relevant query methods (executeQueryStatement, executeRawDataQuery, executeLastDataQuery, executeLastDataQueryForOneDevice, executeLastDataQueryForOnePrefixPath, and executeAggregationQuery) in SessionConnection.java. When a null response is encountered, it now explicitly throws an IoTDBConnectionException("Cannot get statement response from server, response is null") to clearly indicate a communication failure.

Content3: Unit Test & Verification

Added a corresponding unit test testExecuteQueryStatementNullResponse in SessionConnectionTest.java by mocking IClientRPCService.Iface to return null. Verified that SessionConnection throws IoTDBConnectionException instead of crashing with an NPE.


This PR has:

  • been self-reviewed.
  • added unit tests or modified existing tests to cover new code paths, ensuring the threshold for code coverage.

Key changed/added classes (or packages if there are too many classes) in this PR
  • org.apache.iotdb.session.SessionConnection
  • org.apache.iotdb.session.SessionConnectionTest

@HTHou
HTHou requested a review from JackieTien97 October 17, 2026 14:13
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] export data error

1 participant