{"record":{"id":"07dfb8b848700d88","repo":"alibaba/nacos","slug":"listener-is-null","errorCode":null,"errorMessage":"listener is null","messagePattern":"listener is null","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"client/src/main/java/com/alibaba/nacos/client/config/impl/CacheData.java","lineNumber":242,"sourceCode":"        this.lastModifiedTs.set(lastModifiedTs);\n    }\n    \n    public String getType() {\n        return type;\n    }\n    \n    public void setType(String type) {\n        this.type = type;\n    }\n    \n    /**\n     * Add listener if CacheData already set new content, Listener should init lastCallMd5 by CacheData.md5\n     *\n     * @param listener listener\n     */\n    public void addListener(Listener listener) throws NacosException {\n        if (null == listener) {\n            throw new IllegalArgumentException(\"listener is null\");\n        }\n        ManagerListenerWrap wrap;\n        if (listener instanceof AbstractConfigChangeListener) {\n            ConfigResponse cr = new ConfigResponse();\n            cr.setDataId(dataId);\n            cr.setGroup(group);\n            cr.setContent(content);\n            cr.setEncryptedDataKey(encryptedDataKey);\n            configFilterChainManager.doFilter(null, cr);\n            String contentTmp = cr.getContent();\n            wrap = new ManagerListenerWrap(listener, md5, contentTmp);\n        } else {\n            wrap = new ManagerListenerWrap(listener, md5);\n        }\n        \n        if (listeners.addIfAbsent(wrap)) {\n            LOGGER.info(\"[{}] [add-listener] ok, tenant={}, dataId={}, group={}, cnt={}\", envName,\n                tenant, dataId,","sourceCodeStart":224,"sourceCodeEnd":260,"githubUrl":"https://github.com/alibaba/nacos/blob/9b989acdf181d00898f2e8839257bb2b2a3cefe3/client/src/main/java/com/alibaba/nacos/client/config/impl/CacheData.java#L224-L260","documentation":"Thrown by CacheData.addListener when the passed Listener is null. CacheData holds per-config listeners and must wrap each in a ManagerListenerWrap; a null listener would cause an NPE later in the notify path, so it is rejected immediately. This is a programmer error, not a runtime/environment condition.","triggerScenarios":"Calling cacheData.addListener(null) directly, or passing a listener variable that was never initialized / was set to null by a failed factory call.","commonSituations":"Listener reference null due to a missing null-check after construction, conditional logic that skips listener creation but still calls addListener, or a copy-paste error.","solutions":["Null-check the listener before calling addListener and log/skip if absent.","Ensure the listener is constructed unconditionally before registration.","Use a defensive helper that wraps addListener with a null guard."],"exampleFix":"// before\ncacheData.addListener(maybeNullListener);\n\n// after\nif (listener != null) {\n    cacheData.addListener(listener);\n} else {\n    log.warn(\"Skipping listener registration: listener is null\");\n}","handlingStrategy":"validation","validationCode":"if (listener == null) {\n    throw new IllegalArgumentException(\"listener must not be null\");\n}\ncacheData.addListener(listener);","typeGuard":"static boolean isRegistrableListener(Listener l) {\n    return l != null;\n}","tryCatchPattern":"try {\n    cacheData.addListener(listener);\n} catch (IllegalArgumentException e) {\n    if (e.getMessage().contains(\"listener is null\")) {\n        log.warn(\"listener was null, skipping registration\");\n    }\n}","preventionTips":["Null-check listeners before addListener.","Construct listeners unconditionally before registration.","Use Objects.requireNonNull in listener factories."],"tags":["config","listener","validation","client"],"backgroundTag":null,"analyzedSha":"9b989acdf181d00898f2e8839257bb2b2a3cefe3","analyzedAt":"2026-08-14T07:17:31.569Z","schemaVersion":2},"datasetVersion":"2026-08-14T10:17:34.591Z"}