This is an automated email from the ASF dual-hosted git repository. jackietien pushed a commit to branch ty/SessionNPE in repository https://gitbox.apache.org/repos/asf/iotdb.git
commit 7e88dc99ebc6cbe145031d958881087bb4ab2e72 Author: JackieTien97 <[email protected]> AuthorDate: Mon Mar 18 17:27:29 2024 +0800 Fix NPE in Session --- .../java/org/apache/iotdb/session/Session.java | 30 ++++++++++++---------- 1 file changed, 17 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(); + } } } }
