{"record":{"id":"cfb124ab75d281af","repo":"alibaba/nacos","slug":"invalid-param-cfb124","errorCode":"INVALID_PARAM","errorMessage":"AbstractNacosAgentDiscoveryListener must not be null.","messagePattern":"AbstractNacosAgentDiscoveryListener must not be null\\.","errorType":"validation","errorClass":"NacosApiException","httpStatus":null,"severity":"error","filePath":"client/src/main/java/com/alibaba/nacos/client/ai/cache/NacosAgentDiscoveryCacheHolder.java","lineNumber":109,"sourceCode":"        this.updateIntervalMillis = updateIntervalMillis;\n        this.pollingExecutor = pollingExecutor;\n        this.callbackExecutor = callbackExecutor;\n    }\n    \n    /**\n     * Subscribe by periodically executing the same Discover request.\n     *\n     * @param reference Agent reference\n     * @param filter optional filter\n     * @param listener listener identity\n     * @return current snapshot, or {@code null} when absent\n     * @throws NacosException when validation or the initial Discover fails\n     */\n    public synchronized AgentDiscoveryResult subscribe(AgentReference reference,\n        AgentDiscoveryFilter filter, AbstractNacosAgentDiscoveryListener listener)\n        throws NacosException {\n        if (listener == null) {\n            throw new NacosApiException(NacosException.INVALID_PARAM,\n                ErrorCode.PARAMETER_VALIDATE_ERROR,\n                \"AbstractNacosAgentDiscoveryListener must not be null.\");\n        }\n        AgentDiscoveryRequest request =\n            AgentModelUtils.copyDiscoveryRequest(reference, filter, namespaceId);\n        SubscriptionKey key = new SubscriptionKey(buildRequestKey(request), listener);\n        Subscription existing = subscriptions.get(key);\n        if (existing != null) {\n            return AgentModelUtils.copyDiscoveryResult(existing.current);\n        }\n        AgentDiscoveryResult current = discoverOrNull(request);\n        Subscription subscription = new Subscription(key, request, listener, current);\n        subscriptions.put(key, subscription);\n        schedule(subscription);\n        return AgentModelUtils.copyDiscoveryResult(current);\n    }\n    \n    /**","sourceCodeStart":91,"sourceCodeEnd":127,"githubUrl":"https://github.com/alibaba/nacos/blob/9b989acdf181d00898f2e8839257bb2b2a3cefe3/client/src/main/java/com/alibaba/nacos/client/ai/cache/NacosAgentDiscoveryCacheHolder.java#L91-L127","documentation":"Thrown by NacosAgentDiscoveryCacheHolder.subscribe when the caller passes a null listener. Subscribe ties an agent reference to a listener identity that receives periodic Discover snapshots, so a null listener makes the subscription meaningless and is rejected up front with INVALID_PARAM. This is a programmer-contract guard, not a transient runtime condition.","triggerScenarios":"Calling NacosAiService.subscribeAgent(reference, filter, null) or otherwise invoking the cache holder's subscribe(...) with a listener argument that resolved to null (e.g. a listener field not yet initialized, a Map lookup that returned null).","commonSituations":"Listener registered lazily but subscribe called before assignment; DI/lookup of the listener bean failed silently and returned null; refactored call site that dropped the listener argument.","solutions":["Ensure the listener passed to subscribeAgent / NacosAgentDiscoveryCacheHolder.subscribe is non-null before the call.","If the listener is optional in your flow, guard it locally and skip subscribing when it is null.","Check the code path that creates the listener for silent null returns (factory methods, bean lookups)."],"exampleFix":"// before\nservice.subscribeAgent(reference, filter, listener); // listener may be null\n// after\nif (listener != null) {\n    service.subscribeAgent(reference, filter, listener);\n} else {\n    LOGGER.warn(\"Skipping agent discovery subscribe: listener is null for {}\", reference);\n}","handlingStrategy":"validation","validationCode":"if (listener == null) {\n    throw new IllegalArgumentException(\"listener must not be null for agent discovery subscribe\");\n}\nservice.subscribeAgent(reference, filter, listener);","typeGuard":"Objects.requireNonNull(listener, \"listener\"); // or explicit null check before subscribe","tryCatchPattern":null,"preventionTips":["Treat the listener as a required argument and validate it at the call boundary.","Use @NonNull annotations/static analysis to catch null listener arguments at compile time.","Initialize listener fields before calling subscribe."],"tags":["ai","agent-discovery","validation","invalid-param","listener"],"backgroundTag":null,"analyzedSha":"9b989acdf181d00898f2e8839257bb2b2a3cefe3","analyzedAt":"2026-08-14T07:17:31.569Z","schemaVersion":2},"datasetVersion":"2026-08-14T10:17:34.591Z"}