{"record":{"id":"8d56f576e43f340c","repo":"alibaba/nacos","slug":"the-subscriber-has-no-event-publisher","errorCode":null,"errorMessage":"The subscriber has no event publisher","messagePattern":"The subscriber has no event publisher","errorType":"exception","errorClass":"NoSuchElementException","httpStatus":null,"severity":"warning","filePath":"common/src/main/java/com/alibaba/nacos/common/notify/NotifyCenter.java","lineNumber":251,"sourceCode":"                if (ClassUtils.isAssignableFrom(SlowEvent.class, subscribeType)) {\n                    INSTANCE.sharePublisher.removeSubscriber(consumer, subscribeType);\n                } else {\n                    removeSubscriber(consumer, subscribeType);\n                }\n            }\n            return;\n        }\n        \n        final Class<? extends Event> subscribeType = consumer.subscribeType();\n        if (ClassUtils.isAssignableFrom(SlowEvent.class, subscribeType)) {\n            INSTANCE.sharePublisher.removeSubscriber(consumer, subscribeType);\n            return;\n        }\n        \n        if (removeSubscriber(consumer, subscribeType)) {\n            return;\n        }\n        throw new NoSuchElementException(\"The subscriber has no event publisher\");\n    }\n    \n    /**\n     * Remove subscriber.\n     *\n     * @param consumer      subscriber instance.\n     * @param subscribeType subscribeType.\n     * @return whether remove subscriber successfully or not.\n     */\n    private static boolean removeSubscriber(final Subscriber consumer,\n        Class<? extends Event> subscribeType) {\n        \n        final String topic = ClassUtils.getCanonicalName(subscribeType);\n        EventPublisher eventPublisher = INSTANCE.publisherMap.get(topic);\n        if (null == eventPublisher) {\n            return false;\n        }\n        if (eventPublisher instanceof ShardedEventPublisher) {","sourceCodeStart":233,"sourceCodeEnd":269,"githubUrl":"https://github.com/alibaba/nacos/blob/9b989acdf181d00898f2e8839257bb2b2a3cefe3/common/src/main/java/com/alibaba/nacos/common/notify/NotifyCenter.java#L233-L269","documentation":"Thrown by NotifyCenter when unregistering a subscriber that has no associated publisher: the subscriber's subscribeType is not a SlowEvent, it is not in the shared publisher, and removeSubscriber returned false. NoSuchElementException indicates a logic error in subscriber registration/unregistration pairing rather than a transport problem.","triggerScenarios":"Calling NotifyCenter.deregisterSubscriber(consumer)/removeSubscriber for a subscriber/subscribeType combination that was never registered, was already removed, or was registered under a different event type than the one passed at removal.","commonSituations":"Double-unregistering the same subscriber; unregistering with a subscribeType that differs from the one used at registration; subscriber registered via the SlowEvent shared path but removed via the per-type path (or vice versa); cleanup code running for components that were never wired.","solutions":["Match the subscribeType passed to removal with the one used at registration; reuse the same Subscriber instance.","Guard removal: track registered subscribers and only call deregister for ones you actually registered.","Wrap deregistration in try/catch(NoSuchElementException) during teardown so a mismatch does not abort cleanup of other subscribers.","Register/unregister symmetrically in component lifecycle start/stop methods."],"exampleFix":"// before\nNotifyCenter.deregisterSubscriber(sub); // throws if sub was never registered for its type\n\n// after\ntry {\n    NotifyCenter.deregisterSubscriber(sub);\n} catch (NoSuchElementException e) {\n    LOG.debug(\"Subscriber {} already removed for {}\", sub, sub.subscribeType());\n}","handlingStrategy":"try-catch","validationCode":"if (registeredSubscribers.remove(consumer)) {\n    NotifyCenter.deregisterSubscriber(consumer);\n}","typeGuard":null,"tryCatchPattern":"try {\n    NotifyCenter.deregisterSubscriber(consumer);\n} catch (NoSuchElementException e) {\n    log.debug(\"Subscriber {} not registered, ignoring\", consumer);\n}","preventionTips":["Track the subscribers you register and only deregister those.","Use the same Subscriber instance and subscribeType at register and deregister time.","Make teardown idempotent by catching NoSuchElementException during cleanup."],"tags":["event-bus","notify-center","subscriber","lifecycle"],"backgroundTag":null,"analyzedSha":"9b989acdf181d00898f2e8839257bb2b2a3cefe3","analyzedAt":"2026-08-14T07:17:31.569Z","schemaVersion":2},"datasetVersion":"2026-08-14T10:17:34.591Z"}