AdamsF-creator opened a new pull request, #18903:
URL: https://github.com/apache/iotdb/pull/18903

   ## 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.
   
   <hr>
   
   This PR has:
   - [x] been self-reviewed.
   - [x] added unit tests or modified existing tests to cover new code paths, 
ensuring the threshold for code coverage.
   
   <hr>
   
   ##### 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`


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to