From b905f7bd5a58e684004badba483808ded015275e Mon Sep 17 00:00:00 2001 From: KomachiSion <263976490@qq.com> Date: Tue, 15 Sep 2020 13:21:28 +0800 Subject: [PATCH] Fix NullPointerException when no subscriber for slow event --- .../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 3028423f7f7..a2fa996d1db 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 void receiveEvent(Event event) { // 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 a7163938d00..d1abd7c1e73 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 subscribeType() { return ExpireEvent.class; } + @Override public boolean ignoreExpireEvent() { return true; }