{"record":{"id":"facb9286d9361b60","repo":"alibaba/nacos","slug":"agentspec-name-cannot-be-blank","errorCode":null,"errorMessage":"AgentSpec name cannot be blank","messagePattern":"AgentSpec name cannot be blank","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"api/src/main/java/com/alibaba/nacos/api/ai/model/agentspecs/AgentSpecUtils.java","lineNumber":103,"sourceCode":"        if (type != null && !type.trim().isEmpty()) {\n            String safeType = type.trim().replace(\"/\", \".\");\n            return safeType + \"_\" + processedName;\n        } else {\n            return processedName;\n        }\n    }\n    \n    /**\n     * Build the Nacos Config group for a specific AgentSpec version.\n     *\n     * @param agentSpecName name of AgentSpec\n     * @param version       version string, e.g. \"v1\"\n     * @return config group string, e.g. \"agentspec__myworker__v1\"\n     * @throws IllegalArgumentException if agentSpecName or version is blank\n     */\n    public static String buildAgentSpecVersionGroup(String agentSpecName, String version) {\n        if (StringUtils.isBlank(agentSpecName)) {\n            throw new IllegalArgumentException(\"AgentSpec name cannot be blank\");\n        }\n        if (StringUtils.isBlank(version)) {\n            throw new IllegalArgumentException(\"Version cannot be blank\");\n        }\n        return AGENTSPEC_GROUP_PREFIX\n            + NacosAiConfigKeyCodec.encodeVersionedGroupSegment(agentSpecName)\n            + DOUBLE_UNDERSCORE + NacosAiConfigKeyCodec.encodeVersionedGroupSegment(version);\n    }\n    \n}\n","sourceCodeStart":85,"sourceCodeEnd":114,"githubUrl":"https://github.com/alibaba/nacos/blob/9b989acdf181d00898f2e8839257bb2b2a3cefe3/api/src/main/java/com/alibaba/nacos/api/ai/model/agentspecs/AgentSpecUtils.java#L85-L114","documentation":"AgentSpecUtils.buildAgentSpecVersionGroup throws IllegalArgumentException when agentSpecName is blank (null, empty, or whitespace-only). The method constructs a Nacos Config group string and cannot produce a valid group from an empty name.","triggerScenarios":"Calling buildAgentSpecVersionGroup with a null, empty, or whitespace-only agentSpecName parameter. Happens when the name comes from user input that was not validated, or from a deserialized object with a missing name field.","commonSituations":"API endpoint receives a request without the agentSpecName field. A configuration file references an AgentSpec by empty name. A loop or stream operation passes a null name from a map lookup.","solutions":["Validate agentSpecName is non-blank before calling buildAgentSpecVersionGroup.","Use StringUtils.isBlank() pre-check and return early or throw a domain-specific error.","Ensure the caller (controller, service layer) enforces non-blank name at the trust boundary."],"exampleFix":"// before\nString group = AgentSpecUtils.buildAgentSpecVersionGroup(\"\", \"v1\"); // throws\n\n// after\nif (StringUtils.isBlank(agentSpecName)) {\n    throw new IllegalArgumentException(\"agentSpecName required\");\n}\nString group = AgentSpecUtils.buildAgentSpecVersionGroup(agentSpecName, \"v1\");","handlingStrategy":"validation","validationCode":"if (StringUtils.isBlank(agentSpecName)) {\n    throw new IllegalArgumentException(\"agentSpecName is required\");\n}","typeGuard":"public static boolean isAgentSpecNameValid(String name) {\n    return name != null && !name.trim().isEmpty();\n}","tryCatchPattern":"try {\n    group = AgentSpecUtils.buildAgentSpecVersionGroup(name, version);\n} catch (IllegalArgumentException e) {\n    if (e.getMessage().contains(\"AgentSpec name cannot be blank\")) {\n        return badRequest(\"agentSpecName is required\");\n    }\n    throw e;\n}","preventionTips":["Validate non-blank at the API boundary before calling utility methods.","Use StringUtils.isBlank() for consistent whitespace handling.","Reject empty identifiers early in request processing."],"tags":["agentspec","validation","blank","config-group"],"backgroundTag":null,"analyzedSha":"9b989acdf181d00898f2e8839257bb2b2a3cefe3","analyzedAt":"2026-08-14T07:17:31.569Z","schemaVersion":2},"datasetVersion":"2026-08-14T10:17:34.591Z"}