{"record":{"id":"d476181c977929cf","repo":"alibaba/nacos","slug":"400-d47618","errorCode":"400","errorMessage":"Required parameter 'name' type String is not present","messagePattern":"Required parameter 'name' type String is not present","errorType":"validation","errorClass":"NacosApiException","httpStatus":null,"severity":"error","filePath":"api/src/main/java/com/alibaba/nacos/api/naming/pojo/Service.java","lineNumber":128,"sourceCode":"    }\n    \n    public void addMetadata(String key, String value) {\n        this.metadata.put(key, value);\n    }\n    \n    public Selector getSelector() {\n        return selector;\n    }\n    \n    public void setSelector(Selector selector) {\n        this.selector = selector;\n    }\n    \n    @Override\n    public void validate() throws NacosApiException {\n        fillDefaultValue();\n        if (StringUtils.isBlank(name)) {\n            throw new NacosApiException(NacosException.INVALID_PARAM, ErrorCode.PARAMETER_MISSING,\n                \"Required parameter 'name' type String is not present\");\n        }\n    }\n    \n    /**\n     * fill default value.\n     */\n    public void fillDefaultValue() {\n        if (StringUtils.isBlank(namespaceId)) {\n            namespaceId = Constants.DEFAULT_NAMESPACE_ID;\n        }\n        if (StringUtils.isBlank(groupName)) {\n            groupName = Constants.DEFAULT_GROUP;\n        }\n    }\n}\n","sourceCodeStart":110,"sourceCodeEnd":145,"githubUrl":"https://github.com/alibaba/nacos/blob/9b989acdf181d00898f2e8839257bb2b2a3cefe3/api/src/main/java/com/alibaba/nacos/api/naming/pojo/Service.java#L110-L145","documentation":"Thrown by Service.validate() (a NacosApiException, HTTP 400, ErrorCode.PARAMETER_MISSING) when the Service.name field is blank. fillDefaultValue() runs first and fills in defaults for namespaceId and groupName, but name is the primary registry identifier and must be supplied by the caller.","triggerScenarios":"Calling NamingService.registerInstance / service create or update with a Service POJO whose name was never set; submitting an admin/console create-service form with an empty serviceName field; constructing Service from deserialized JSON where the name key was dropped.","commonSituations":"Console form validation gap; client code building a Service from untrusted user input without checking the name; migration or copy-paste that loses the setName call.","solutions":["Call service.setName(\"...\") with a non-blank value before register/create/validate.","Validate user input at the controller/form boundary so blank names never reach the API.","If building Service from JSON, confirm the name field is present and non-empty after parsing."],"exampleFix":"// before\nService s = new Service();\ns.setGroupName(\"DEFAULT_GROUP\");\nnamingService.createService(s);  // throws 540\n\n// after\nService s = new Service();\ns.setName(\"order-service\");\ns.setGroupName(\"DEFAULT_GROUP\");\nnamingService.createService(s);","handlingStrategy":"validation","validationCode":"if (service == null || StringUtils.isBlank(service.getName())) {\n    throw new IllegalArgumentException(\"service.name is required\");\n}","typeGuard":null,"tryCatchPattern":"try {\n    service.validate();\n} catch (NacosApiException e) {\n    if (e.getErrCode() == NacosException.INVALID_PARAM\n            && e.getMessage().contains(\"'name'\")) {\n        // surface a user-friendly 'service name required' error\n    }\n}","preventionTips":["Centralize Service construction in a factory that enforces required fields.","Always set name before register/create/validate.","Validate form input at the controller boundary so blank names never reach the API."],"tags":["naming","validation","parameter","service"],"backgroundTag":null,"analyzedSha":"9b989acdf181d00898f2e8839257bb2b2a3cefe3","analyzedAt":"2026-08-14T07:17:31.569Z","schemaVersion":2},"datasetVersion":"2026-08-14T10:17:34.591Z"}