apolloconfig/apollo · error · BadRequestException
ServerConfig.Key cannot be blank
Error message
ServerConfig.Key cannot be blank
What it means
Thrown by validateServerConfig when the ServerConfig body is non-null but its key field is blank (null, empty, or whitespace-only). Apollo requires every server config entry to have a meaningful key, since the key is used to look up and override configuration values at runtime.
Source
Thrown at apollo-portal/src/main/java/com/ctrip/framework/apollo/openapi/v1/controller/PortalManagementController.java:919
&& !CONFLICT_ACTION_IGNORE.equals(conflictAction)) {
throw new BadRequestException("ConflictAction is incorrect.");
}
}
private String resolveConflictAction(String conflictAction) {
if (StringUtils.isEmpty(conflictAction)) {
return CONFLICT_ACTION_IGNORE;
}
validateConflictAction(conflictAction);
return conflictAction;
}
private void validateServerConfig(ServerConfig serverConfig) {
if (serverConfig == null) {
throw new BadRequestException("ServerConfig can not be null");
}
if (!org.springframework.util.StringUtils.hasText(serverConfig.getKey())) {
throw new BadRequestException("ServerConfig.Key cannot be blank");
}
if (!org.springframework.util.StringUtils.hasText(serverConfig.getValue())) {
throw new BadRequestException("ServerConfig.Value cannot be blank");
}
}
private Date parseConsumerExpires(String expires) {
if (!org.springframework.util.StringUtils.hasText(expires)) {
return DEFAULT_EXPIRES;
}
try {
return new SimpleDateFormat("yyyyMMddHHmmss").parse(expires);
} catch (ParseException e) {
throw new BadRequestException("Invalid expires format: %s", expires);
}
}
private Date parseAuditDate(String value) {View on GitHub (pinned to d95fc18d11)
Solutions
- Include a non-blank key in the JSON body, e.g. {"key":"my.config.key","value":"123"}.
- Verify the JSON uses camelCase field name 'key'.
- Trim whitespace from the key before sending.
Example fix
// before
{"key":"","value":"30"}
// after
{"key":"timeout.seconds","value":"30"} Defensive patterns
Strategy: validation
Validate before calling
// Validate key is non-blank before sending
if (!org.springframework.util.StringUtils.hasText(serverConfig.getKey())) {
throw new IllegalArgumentException("ServerConfig key must not be blank");
} Type guard
function hasNonBlankKey(body: { key?: string }): boolean {
return typeof body.key === 'string' && body.key.trim().length > 0;
} Prevention
- Validate all required string fields client-side using hasText-equivalent checks.
- Use builder patterns that reject blank keys at construction.
- Include key and value in every ServerConfig request as a minimum.
When it happens
Trigger: A server-config create/update request with a JSON body where the key field is missing, null, empty string, or contains only whitespace.
Common situations: The caller included a value but forgot the key; the key was programmatically set to an empty string; or field-name casing caused the key to not bind.
Related errors
- ServerConfig can not be null
- ServerConfig.Value cannot be blank
- userIds should not be null or empty
- AppId not equal. AppId in path = %s, AppId in payload = %s
- operator should not be null or empty
AI-assisted analysis of apolloconfig/apollo@d95fc18d11 (2026-08-14).
Data as JSON: /api/errors/ee91db0a7e673d2e.
Report an issue: GitHub.