{"record":{"id":"043cf4f7343c5e94","repo":"alibaba/nacos","slug":"fieldname-must-not-be-null","errorCode":null,"errorMessage":"${fieldName} must not be null","messagePattern":"(.+?) must not be null","errorType":"exception","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"ai/src/main/java/com/alibaba/nacos/ai/remote/handler/agent/AgentDiscoveryRpcRequestHandler.java","lineNumber":72,"sourceCode":"    @Secured(action = ActionTypes.READ, signType = SignType.AI)\n    public AgentDiscoveryResponse handle(AgentDiscoveryRpcRequest request, RequestMeta meta)\n        throws NacosException {\n        AgentDiscoveryResponse response = new AgentDiscoveryResponse();\n        try {\n            requireRequest(request.getDiscoveryRequest(), \"discoveryRequest\");\n            request.getDiscoveryRequest().setNamespaceId(NamespaceUtil.processNamespaceParameter(\n                request.getDiscoveryRequest().getNamespaceId()));\n            response.setDiscoveryResult(\n                discoveryService.discover(request.getDiscoveryRequest()));\n        } catch (Exception e) {\n            AgentGrpcResponseErrorMapper.apply(response, e);\n        }\n        return response;\n    }\n    \n    private <T> T requireRequest(T value, String fieldName) {\n        if (value == null) {\n            throw new IllegalArgumentException(fieldName + \" must not be null\");\n        }\n        return value;\n    }\n}\n","sourceCodeStart":54,"sourceCodeEnd":77,"githubUrl":"https://github.com/alibaba/nacos/blob/9b989acdf181d00898f2e8839257bb2b2a3cefe3/ai/src/main/java/com/alibaba/nacos/ai/remote/handler/agent/AgentDiscoveryRpcRequestHandler.java#L54-L77","documentation":"Thrown (as IllegalArgumentException) by the RAD AgentDiscovery gRPC handler when the inner `discoveryRequest` of AgentDiscoveryRpcRequest is null. The handler's requireRequest() guard rejects nulls; AgentGrpcResponseErrorMapper then maps IllegalArgumentException to PARAMETER_VALIDATE_ERROR on the response.","triggerScenarios":"Sending an AgentDiscoveryRpcRequest whose getDiscoveryRequest() returns null. The handler calls requireRequest(request.getDiscoveryRequest(), \"discoveryRequest\") as the first step inside the try block.","commonSituations":"Client wraps the outer RPC envelope but leaves the inner discovery descriptor unset; a protobuf/JSON field-name mismatch drops the nested object; reusing a request object whose inner field was cleared.","solutions":["Populate the nested discoveryRequest (with namespaceId, agentName, etc.) before sending.","Assert request.getDiscoveryRequest() != null client-side before invoking discovery.","Construct the outer request via a builder that mandates the inner discoveryRequest."],"exampleFix":"// before\nAgentDiscoveryRpcRequest req = new AgentDiscoveryRpcRequest();\n// discoveryRequest never set -> error\n\n// after\nreq.setDiscoveryRequest(buildDiscoveryRequest());","handlingStrategy":"validation","validationCode":"Objects.requireNonNull(request.getDiscoveryRequest(), \"discoveryRequest\");","typeGuard":"boolean hasDiscoveryRequest(AgentDiscoveryRpcRequest r) {\n    return r != null && r.getDiscoveryRequest() != null;\n}","tryCatchPattern":"// after the gRPC call, inspect the response error code\nif (response.getErrorCode() != 0) {\n    log.warn(\"discovery failed: {}\", response.getMessage());\n}","preventionTips":["Always populate the nested discoveryRequest before sending the outer envelope.","Watch the response error code/message since IllegalArgumentException is mapped, not thrown."],"tags":["rad","grpc","validation","agent-discovery","illegal-argument"],"backgroundTag":null,"analyzedSha":"9b989acdf181d00898f2e8839257bb2b2a3cefe3","analyzedAt":"2026-08-14T07:17:31.569Z","schemaVersion":2},"datasetVersion":"2026-08-14T10:17:34.591Z"}