This is an automated email from the ASF dual-hosted git repository.

jackietien pushed a commit to branch rc/2.0.5
in repository https://gitbox.apache.org/repos/asf/iotdb.git

commit 12e6bdbf4ab5e01eba49741b3f647e5b1b88f691
Author: Jackie Tien <[email protected]>
AuthorDate: Mon Jul 21 14:03:24 2025 +0800

    Avoid NPE in dealWithException of QueryExecution
    
    (cherry picked from commit 3021737d9b79b9bd78947ba53c06f15e175556ca)
---
 .../queryengine/plan/execution/QueryExecution.java | 32 ++++++++++++----------
 1 file changed, 17 insertions(+), 15 deletions(-)

diff --git 
a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/execution/QueryExecution.java
 
b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/execution/QueryExecution.java
index 3af3c32ec9d..3f4e54a59d1 100644
--- 
a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/execution/QueryExecution.java
+++ 
b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/execution/QueryExecution.java
@@ -462,23 +462,25 @@ public class QueryExecution implements IQueryExecution {
   private void dealWithException(Throwable t) throws IoTDBException {
     t = getRootCause(t);
     stateMachine.transitionToFailed(t);
-    if (stateMachine.getFailureStatus() != null) {
-      throw new IoTDBException(
-          stateMachine.getFailureStatus().getMessage(), 
stateMachine.getFailureStatus().code);
-    } else if (stateMachine.getFailureException() != null) {
+    TSStatus status = stateMachine.getFailureStatus();
+    if (status != null) {
+      throw new IoTDBException(status.getMessage(), status.code);
+    } else {
       Throwable rootCause = stateMachine.getFailureException();
-      if (rootCause instanceof IoTDBRuntimeException) {
-        throw (IoTDBRuntimeException) rootCause;
-      } else if (rootCause instanceof IoTDBException) {
-        throw (IoTDBException) rootCause;
-      } else if (rootCause instanceof DateTimeParseException) {
-        throw new IoTDBRuntimeException(
-            rootCause.getMessage(), DATE_OUT_OF_RANGE.getStatusCode(), true);
+      if (rootCause != null) {
+        if (rootCause instanceof IoTDBRuntimeException) {
+          throw (IoTDBRuntimeException) rootCause;
+        } else if (rootCause instanceof IoTDBException) {
+          throw (IoTDBException) rootCause;
+        } else if (rootCause instanceof DateTimeParseException) {
+          throw new IoTDBRuntimeException(
+              rootCause.getMessage(), DATE_OUT_OF_RANGE.getStatusCode(), true);
+        }
+        throw new IoTDBException(rootCause, 
TSStatusCode.EXECUTE_STATEMENT_ERROR.getStatusCode());
+      } else {
+        throwIfUnchecked(t);
+        throw new IoTDBException(t, 
TSStatusCode.QUERY_PROCESS_ERROR.getStatusCode());
       }
-      throw new IoTDBException(rootCause, 
TSStatusCode.EXECUTE_STATEMENT_ERROR.getStatusCode());
-    } else {
-      throwIfUnchecked(t);
-      throw new IoTDBException(t, 
TSStatusCode.QUERY_PROCESS_ERROR.getStatusCode());
     }
   }
 

Reply via email to