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

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


The following commit(s) were added to refs/heads/master by this push:
     new 1ca73226e7d Fix NPE in SessionConnection while first node in nodeurls 
is unavailable
1ca73226e7d is described below

commit 1ca73226e7d7f7041eeaf52b4c4af98848182f2e
Author: Jackie Tien <[email protected]>
AuthorDate: Tue Mar 19 17:55:46 2024 +0800

    Fix NPE in SessionConnection while first node in nodeurls is unavailable
---
 .../java/org/apache/iotdb/session/Session.java     | 30 ++++++++++++----------
 .../apache/iotdb/session/SessionConnection.java    |  4 +++
 2 files changed, 21 insertions(+), 13 deletions(-)

diff --git 
a/iotdb-client/session/src/main/java/org/apache/iotdb/session/Session.java 
b/iotdb-client/session/src/main/java/org/apache/iotdb/session/Session.java
index 4d0ad33efd7..85759d6bea9 100644
--- a/iotdb-client/session/src/main/java/org/apache/iotdb/session/Session.java
+++ b/iotdb-client/session/src/main/java/org/apache/iotdb/session/Session.java
@@ -1224,22 +1224,26 @@ public class Session implements ISession {
     // remove the cached broken leader session
     if (enableRedirection) {
       TEndPoint endPoint = null;
-      for (Iterator<Entry<TEndPoint, SessionConnection>> it =
-              endPointToSessionConnection.entrySet().iterator();
-          it.hasNext(); ) {
-        Entry<TEndPoint, SessionConnection> entry = it.next();
-        if (entry.getValue().equals(sessionConnection)) {
-          endPoint = entry.getKey();
-          it.remove();
-          break;
+      if (endPointToSessionConnection != null) {
+        for (Iterator<Entry<TEndPoint, SessionConnection>> it =
+                endPointToSessionConnection.entrySet().iterator();
+            it.hasNext(); ) {
+          Entry<TEndPoint, SessionConnection> entry = it.next();
+          if (entry.getValue().equals(sessionConnection)) {
+            endPoint = entry.getKey();
+            it.remove();
+            break;
+          }
         }
       }
 
-      for (Iterator<Entry<String, TEndPoint>> it = 
deviceIdToEndpoint.entrySet().iterator();
-          it.hasNext(); ) {
-        Entry<String, TEndPoint> entry = it.next();
-        if (entry.getValue().equals(endPoint)) {
-          it.remove();
+      if (deviceIdToEndpoint != null) {
+        for (Iterator<Entry<String, TEndPoint>> it = 
deviceIdToEndpoint.entrySet().iterator();
+            it.hasNext(); ) {
+          Entry<String, TEndPoint> entry = it.next();
+          if (entry.getValue().equals(endPoint)) {
+            it.remove();
+          }
         }
       }
     }
diff --git 
a/iotdb-client/session/src/main/java/org/apache/iotdb/session/SessionConnection.java
 
b/iotdb-client/session/src/main/java/org/apache/iotdb/session/SessionConnection.java
index 7f29e5e9b3f..bb0f53efc2d 100644
--- 
a/iotdb-client/session/src/main/java/org/apache/iotdb/session/SessionConnection.java
+++ 
b/iotdb-client/session/src/main/java/org/apache/iotdb/session/SessionConnection.java
@@ -80,6 +80,7 @@ import java.util.ArrayList;
 import java.util.Collections;
 import java.util.List;
 import java.util.StringJoiner;
+import java.util.concurrent.ConcurrentHashMap;
 import java.util.concurrent.TimeUnit;
 import java.util.function.Supplier;
 
@@ -1406,6 +1407,9 @@ public class SessionConnection {
         session.removeBrokenSessionConnection(this);
         session.defaultEndPoint = this.endPoint;
         session.defaultSessionConnection = this;
+        if (session.endPointToSessionConnection == null) {
+          session.endPointToSessionConnection = new ConcurrentHashMap<>();
+        }
         session.endPointToSessionConnection.put(session.defaultEndPoint, this);
         break;
       }

Reply via email to