{"record":{"id":"e8639fb3b609f0de","repo":"alibaba/nacos","slug":"agent-draft-request-must-not-be-null","errorCode":null,"errorMessage":"Agent draft request must not be null","messagePattern":"Agent draft request must not be null","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":400,"severity":"error","filePath":"ai/src/main/java/com/alibaba/nacos/ai/service/agent/AgentOperationService.java","lineNumber":242,"sourceCode":"        return persistenceService.listAgentVersions(namespaceId, agentName, status, pageNo,\n            pageSize);\n    }\n    \n    /**\n     * Create a new Agent draft Version, creating Agent metadata when it does not exist.\n     *\n     * <p>An equivalent request may be retried idempotently, but this operation never replaces\n     * existing draft content.</p>\n     *\n     * @param namespaceId namespace identifier\n     * @param request draft request\n     * @return verified draft detail\n     * @throws NacosException when creation fails\n     */\n    public AgentVersionDetail createDraft(String namespaceId, AgentDraftCreateRequest request)\n        throws NacosException {\n        if (request == null) {\n            throw new IllegalArgumentException(\"Agent draft request must not be null\");\n        }\n        AgentValidationUtils.validateNamespaceId(namespaceId);\n        request.validate();\n        String agentName = request.getAgentName();\n        AgentVersionDetail draft = toDraft(request);\n        AiResource meta = resourceManager.findMeta(namespaceId, agentName, RESOURCE_TYPE);\n        AgentVersionDetail result;\n        if (meta == null) {\n            requireInitialDraftContent(request);\n            result = persistenceService.createInitialDraft(toInitialAgent(namespaceId, request),\n                draft);\n        } else {\n            VisibilityHelper.checkWritableResource(meta);\n            if (hasInitialAgentMetadata(request)) {\n                requireInitialDraftContent(request);\n                if (!request.getVersion().equals(\n                    AiResourceManager.requireVersionInfo(meta).getEditingVersion())) {\n                    throw new IllegalArgumentException(","sourceCodeStart":224,"sourceCodeEnd":260,"githubUrl":"https://github.com/alibaba/nacos/blob/9b989acdf181d00898f2e8839257bb2b2a3cefe3/ai/src/main/java/com/alibaba/nacos/ai/service/agent/AgentOperationService.java#L224-L260","documentation":"Thrown by AgentOperationService.createDraft as an IllegalArgumentException when the request parameter is null. Similar to error 115, this is a precondition guard on the public API. The method signature declares throws NacosException, but this specific null-check throws an unchecked IllegalArgumentException.","triggerScenarios":"Calling createDraft(namespaceId, null). Controller deserialization yields null for an empty/malformed request body. Code path where the AgentDraftCreateRequest is conditionally built.","commonSituations":"Empty POST body on the draft-create endpoint. JSON parse error swallowed, producing null. Refactoring that removed request construction in an edge-case branch.","solutions":["Validate the request is non-null at the controller layer before calling createDraft.","Ensure the API client always sends a well-formed request body.","Return HTTP 400 from the controller if the body is missing rather than letting the service throw."],"exampleFix":"// before\nagentOperationService.createDraft(ns, null);\n\n// after\nif (request == null) {\n    return ResponseEntity.badRequest().body(\"request body required\");\n}\nagentOperationService.createDraft(ns, request);","handlingStrategy":"type-guard","validationCode":"// Null-check at the controller or caller layer\nif (request == null) {\n    return ResponseEntity.badRequest().body(\"draft request body is required\");\n}\nagentOperationService.createDraft(namespaceId, request);","typeGuard":"public static boolean isValidDraftRequest(AgentDraftCreateRequest request) {\n    return request != null && StringUtils.isNotBlank(request.getAgentName());\n}","tryCatchPattern":"try {\n    agentOperationService.createDraft(ns, request);\n} catch (IllegalArgumentException e) {\n    if (e.getMessage().contains(\"must not be null\")) {\n        return ResponseEntity.badRequest().body(e.getMessage());\n    }\n    throw e;\n}","preventionTips":["Validate request body is non-null at the controller layer.","Use @NotNull on the request DTO field in the controller signature.","Return 400 Bad Request early for empty bodies."],"tags":["agent","null-check","illegal-argument","draft","create","programming-error"],"backgroundTag":null,"analyzedSha":"9b989acdf181d00898f2e8839257bb2b2a3cefe3","analyzedAt":"2026-08-14T07:17:31.569Z","schemaVersion":2},"datasetVersion":"2026-08-14T10:17:34.591Z"}