From 565557c5c5b5d22cbcedfdcdad4289e5a4461a96 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=A8=E7=BF=8A=20SionYang?= <263976490@qq.com> Date: Tue, 15 Sep 2020 14:50:57 +0800 Subject: [PATCH] Fix NullPointerException when no subscriber for slow event (#3835) --- .../alibaba/nacos/common/notify/DefaultSharePublisher.java | 4 ++++ .../com/alibaba/nacos/common/notify/NotifyCenterTest.java | 1 + 2 files changed, 5 insertions(+) diff --git a/common/src/main/java/com/alibaba/nacos/common/notify/DefaultSharePublisher.java b/common/src/main/java/com/alibaba/nacos/common/notify/DefaultSharePublisher.java index 3028423f7..a2fa996d1 100644 --- a/common/src/main/java/com/alibaba/nacos/common/notify/DefaultSharePublisher.java +++ b/common/src/main/java/com/alibaba/nacos/common/notify/DefaultSharePublisher.java @@ -96,6 +96,10 @@ public class DefaultSharePublisher extends DefaultPublisher { // Get for Map, the algorithm is O(1). Set subscribers = subMappings.get(slowEventType); + if (null == subscribers) { + LOGGER.debug("[NotifyCenter] No subscribers for slow event {}", slowEventType.getName()); + return; + } // Notification single event subscriber for (Subscriber subscriber : subscribers) { diff --git a/common/src/test/java/com/alibaba/nacos/common/notify/NotifyCenterTest.java b/common/src/test/java/com/alibaba/nacos/common/notify/NotifyCenterTest.java index a7163938d..d1abd7c1e 100644 --- a/common/src/test/java/com/alibaba/nacos/common/notify/NotifyCenterTest.java +++ b/common/src/test/java/com/alibaba/nacos/common/notify/NotifyCenterTest.java @@ -132,6 +132,7 @@ public class NotifyCenterTest { return ExpireEvent.class; } + @Override public boolean ignoreExpireEvent() { return true; }