{"record":{"id":"cd40d76d7d1e414f","repo":"alibaba/nacos","slug":"agent-publish-request-must-not-be-null","errorCode":null,"errorMessage":"Agent publish request must not be null","messagePattern":"Agent publish request must not be null","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"ai/src/main/java/com/alibaba/nacos/ai/service/agent/AgentPublishApplicationService.java","lineNumber":59,"sourceCode":"    \n    private final AgentOperationService operationService;\n    \n    public AgentPublishApplicationService(AgentOperationService operationService) {\n        this.operationService = operationService;\n    }\n    \n    /**\n     * Publish one exact Agent Version and optionally submit it.\n     *\n     * @param namespaceId effective namespace\n     * @param request publication request\n     * @return resulting exact Version detail\n     * @throws NacosException when validation, persistence, or submit fails\n     */\n    public AgentVersionDetail publish(String namespaceId, AgentPublishRequest request)\n        throws NacosException {\n        if (request == null) {\n            throw new IllegalArgumentException(\"Agent publish request must not be null\");\n        }\n        AgentValidationUtils.validateNamespaceId(namespaceId);\n        request.validate();\n        AgentVersionDetail current = findEquivalent(namespaceId, request);\n        if (current == null) {\n            try {\n                current = operationService.createDraft(namespaceId, request);\n            } catch (NacosException createFailure) {\n                current = recoverEquivalent(namespaceId, request, createFailure);\n            }\n        }\n        if (!request.isAutoSubmit()) {\n            requireStatus(current, AiConstants.Agent.VERSION_STATUS_DRAFT);\n            return current;\n        }\n        if (!AiConstants.Agent.VERSION_STATUS_DRAFT.equals(current.getStatus())) {\n            return requireSubmittedState(current);\n        }","sourceCodeStart":41,"sourceCodeEnd":77,"githubUrl":"https://github.com/alibaba/nacos/blob/9b989acdf181d00898f2e8839257bb2b2a3cefe3/ai/src/main/java/com/alibaba/nacos/ai/service/agent/AgentPublishApplicationService.java#L41-L77","documentation":"The AgentPublishApplicationService.publish method requires a non-null AgentPublishRequest. This is the entry guard for the idempotent Agent draft-and-submit pipeline used by the client publish API. A null request means no publication data was provided, which is a programming or binding error.","triggerScenarios":"Calling AgentPublishApplicationService.publish(namespaceId, null), or the client publish API endpoint with a missing/empty request body that deserializes to null.","commonSituations":"An SDK caller passes null instead of a constructed request. The HTTP request body is empty or malformed. A retry or callback invokes publish without reconstructing the request object.","solutions":["Construct and populate an AgentPublishRequest before calling publish.","Validate non-null at the controller/client boundary before delegating to the service.","Ensure the HTTP request body is valid JSON with agentName, version, and callInterfaces."],"exampleFix":"// before\nservice.publish(ns, null); // throws\n\n// after\nAgentPublishRequest req = new AgentPublishRequest();\nreq.setAgentName(\"my-agent\");\nreq.setVersion(\"1.0.0\");\nreq.setCallInterfaces(List.of(callInterface));\nreq.setAutoSubmit(true);\nservice.publish(ns, req);","handlingStrategy":"validation","validationCode":"if (request == null) {\n    throw new IllegalArgumentException(\"Agent publish request must not be null\");\n}","typeGuard":"boolean isPublishable(AgentPublishRequest req) {\n    return req != null && req.getAgentName() != null && req.getVersion() != null\n        && req.getCallInterfaces() != null;\n}","tryCatchPattern":null,"preventionTips":["Validate the request object is non-null before calling publish.","Use @RequestBody(required = true) at the controller to reject empty bodies early.","Construct AgentPublishRequest via a builder that enforces required fields."],"tags":["agent","ai-registry","validation","publish","null-check"],"backgroundTag":null,"analyzedSha":"9b989acdf181d00898f2e8839257bb2b2a3cefe3","analyzedAt":"2026-08-14T07:17:31.569Z","schemaVersion":2},"datasetVersion":"2026-08-14T10:17:34.591Z"}