alibaba/nacos · error · NacosApiException
400
400
Error message
Required parameter 'name' type String is not present
What it means
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.
Source
Thrown at api/src/main/java/com/alibaba/nacos/api/naming/pojo/Service.java:128
}
public void addMetadata(String key, String value) {
this.metadata.put(key, value);
}
public Selector getSelector() {
return selector;
}
public void setSelector(Selector selector) {
this.selector = selector;
}
@Override
public void validate() throws NacosApiException {
fillDefaultValue();
if (StringUtils.isBlank(name)) {
throw new NacosApiException(NacosException.INVALID_PARAM, ErrorCode.PARAMETER_MISSING,
"Required parameter 'name' type String is not present");
}
}
/**
* fill default value.
*/
public void fillDefaultValue() {
if (StringUtils.isBlank(namespaceId)) {
namespaceId = Constants.DEFAULT_NAMESPACE_ID;
}
if (StringUtils.isBlank(groupName)) {
groupName = Constants.DEFAULT_GROUP;
}
}
}
View on GitHub (pinned to 9b989acdf1)
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.
Example fix
// before
Service s = new Service();
s.setGroupName("DEFAULT_GROUP");
namingService.createService(s); // throws 540
// after
Service s = new Service();
s.setName("order-service");
s.setGroupName("DEFAULT_GROUP");
namingService.createService(s); Defensive patterns
Strategy: validation
Validate before calling
if (service == null || StringUtils.isBlank(service.getName())) {
throw new IllegalArgumentException("service.name is required");
} Try / catch
try {
service.validate();
} catch (NacosApiException e) {
if (e.getErrCode() == NacosException.INVALID_PARAM
&& e.getMessage().contains("'name'")) {
// surface a user-friendly 'service name required' error
}
} Prevention
- 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.
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- Param 'serviceName' is illegal, serviceName is blank
- Param 'groupName' is illegal, groupName is blank
- SELECTOR_ERROR
- PARAMETER_MISSING
- PARAMETER_MISSING
AI-assisted analysis of alibaba/nacos@9b989acdf1 (2026-08-14).
Data as JSON: /api/errors/d476181c977929cf.
Report an issue: GitHub.