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

zihaoxiang pushed a commit to branch dev
in repository https://gitbox.apache.org/repos/asf/dolphinscheduler.git


The following commit(s) were added to refs/heads/dev by this push:
     new b47b3c13cb [Chore] Prevent NPE when handling zk connection events 
(#17526)
b47b3c13cb is described below

commit b47b3c13cb67636c5bb9a7f9dec3a571a0571aec
Author: huangsheng <[email protected]>
AuthorDate: Fri Sep 26 18:18:55 2025 +0800

    [Chore] Prevent NPE when handling zk connection events (#17526)
---
 .../zookeeper/ZookeeperTreeCacheListenerAdapter.java     | 16 ++++++++++++++++
 1 file changed, 16 insertions(+)

diff --git 
a/dolphinscheduler-registry/dolphinscheduler-registry-plugins/dolphinscheduler-registry-zookeeper/src/main/java/org/apache/dolphinscheduler/plugin/registry/zookeeper/ZookeeperTreeCacheListenerAdapter.java
 
b/dolphinscheduler-registry/dolphinscheduler-registry-plugins/dolphinscheduler-registry-zookeeper/src/main/java/org/apache/dolphinscheduler/plugin/registry/zookeeper/ZookeeperTreeCacheListenerAdapter.java
index da35f21bbf..3a8fb1cd82 100644
--- 
a/dolphinscheduler-registry/dolphinscheduler-registry-plugins/dolphinscheduler-registry-zookeeper/src/main/java/org/apache/dolphinscheduler/plugin/registry/zookeeper/ZookeeperTreeCacheListenerAdapter.java
+++ 
b/dolphinscheduler-registry/dolphinscheduler-registry-plugins/dolphinscheduler-registry-zookeeper/src/main/java/org/apache/dolphinscheduler/plugin/registry/zookeeper/ZookeeperTreeCacheListenerAdapter.java
@@ -26,12 +26,19 @@ import org.apache.curator.framework.recipes.cache.ChildData;
 import org.apache.curator.framework.recipes.cache.TreeCacheEvent;
 import org.apache.curator.framework.recipes.cache.TreeCacheListener;
 
+import java.util.EnumSet;
+
 public class ZookeeperTreeCacheListenerAdapter implements TreeCacheListener {
 
     private final String watchedPath;
 
     private final SubscribeListener listener;
 
+    private static final EnumSet<TreeCacheEvent.Type> NODE_CHANGE_EVENTS =
+            EnumSet.of(TreeCacheEvent.Type.NODE_REMOVED,
+                    TreeCacheEvent.Type.NODE_UPDATED,
+                    TreeCacheEvent.Type.NODE_ADDED);
+
     public ZookeeperTreeCacheListenerAdapter(final String watchedPath, final 
SubscribeListener listener) {
         this.listener = listener;
         this.watchedPath = watchedPath;
@@ -39,6 +46,11 @@ public class ZookeeperTreeCacheListenerAdapter implements 
TreeCacheListener {
 
     @Override
     public void childEvent(final CuratorFramework curatorFramework, final 
TreeCacheEvent event) {
+        // When the event type is INITIALIZED or CONNECTION_SUSPENDED or 
CONNECTION_LOST or CONNECTION_RECONNECTED, the
+        // data in the event is null by default
+        if (!isNodeChangeEvent(event)) {
+            return;
+        }
         final String eventPath = event.getData().getPath();
         switch (listener.getSubscribeScope()) {
             case PATH_ONLY:
@@ -59,6 +71,10 @@ public class ZookeeperTreeCacheListenerAdapter implements 
TreeCacheListener {
         }
     }
 
+    private boolean isNodeChangeEvent(TreeCacheEvent event) {
+        return NODE_CHANGE_EVENTS.contains(event.getType());
+    }
+
     private Event convertToEvent(TreeCacheEvent event, String watchedPath) {
 
         Event.Type type;

Reply via email to