alibaba/nacos · error · IllegalArgumentException

${fieldName} must not be null

Error message

${fieldName} must not be null

What it means

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.

Source

Thrown at ai/src/main/java/com/alibaba/nacos/ai/remote/handler/agent/AgentDiscoveryRpcRequestHandler.java:72

    @Secured(action = ActionTypes.READ, signType = SignType.AI)
    public AgentDiscoveryResponse handle(AgentDiscoveryRpcRequest request, RequestMeta meta)
        throws NacosException {
        AgentDiscoveryResponse response = new AgentDiscoveryResponse();
        try {
            requireRequest(request.getDiscoveryRequest(), "discoveryRequest");
            request.getDiscoveryRequest().setNamespaceId(NamespaceUtil.processNamespaceParameter(
                request.getDiscoveryRequest().getNamespaceId()));
            response.setDiscoveryResult(
                discoveryService.discover(request.getDiscoveryRequest()));
        } catch (Exception e) {
            AgentGrpcResponseErrorMapper.apply(response, e);
        }
        return response;
    }
    
    private <T> T requireRequest(T value, String fieldName) {
        if (value == null) {
            throw new IllegalArgumentException(fieldName + " must not be null");
        }
        return value;
    }
}

View on GitHub (pinned to 9b989acdf1)

Solutions

  1. Populate the nested discoveryRequest (with namespaceId, agentName, etc.) before sending.
  2. Assert request.getDiscoveryRequest() != null client-side before invoking discovery.
  3. Construct the outer request via a builder that mandates the inner discoveryRequest.

Example fix

// before
AgentDiscoveryRpcRequest req = new AgentDiscoveryRpcRequest();
// discoveryRequest never set -> error

// after
req.setDiscoveryRequest(buildDiscoveryRequest());
Defensive patterns

Strategy: validation

Validate before calling

Objects.requireNonNull(request.getDiscoveryRequest(), "discoveryRequest");

Type guard

boolean hasDiscoveryRequest(AgentDiscoveryRpcRequest r) {
    return r != null && r.getDiscoveryRequest() != null;
}

Try / catch

// after the gRPC call, inspect the response error code
if (response.getErrorCode() != 0) {
    log.warn("discovery failed: {}", response.getMessage());
}

Prevention

When it happens

Trigger: Sending an AgentDiscoveryRpcRequest whose getDiscoveryRequest() returns null. The handler calls requireRequest(request.getDiscoveryRequest(), "discoveryRequest") as the first step inside the try block.

Common situations: 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.

Related errors


AI-assisted analysis of alibaba/nacos@9b989acdf1 (2026-08-14). Data as JSON: /api/errors/043cf4f7343c5e94. Report an issue: GitHub.