apolloconfig/apollo · error · BadRequestException
ServerConfig can not be null
Error message
ServerConfig can not be null
What it means
Thrown by validateServerConfig when the ServerConfig request body is entirely null. Apollo's server-config management endpoint expects a JSON body that deserializes to a non-null ServerConfig object. This is the first check in a validation chain that also verifies key and value fields.
Source
Thrown at apollo-portal/src/main/java/com/ctrip/framework/apollo/openapi/v1/controller/PortalManagementController.java:916
private void validateConflictAction(String conflictAction) {
if (!CONFLICT_ACTION_COVER.equals(conflictAction)
&& !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);
}View on GitHub (pinned to d95fc18d11)
Solutions
- Send a valid JSON body with at least key and value fields, e.g. {"key":"my.key","value":"my-value"}.
- Ensure the Content-Type header is application/json.
- If using a client library, verify the request object is instantiated and not null before serialization.
Example fix
// before
POST /server-config
(empty body)
// after
POST /server-config
{"key":"timeout","value":"30"} Defensive patterns
Strategy: validation
Validate before calling
// Validate ServerConfig is non-null before sending
if (serverConfig == null) {
throw new IllegalArgumentException("ServerConfig body must not be null");
} Type guard
function isNonNullServerConfig(body: unknown): body is { key: string; value: string } {
return typeof body === 'object' && body !== null;
} Prevention
- Always construct a ServerConfig object before serializing.
- Set Content-Type: application/json on all POST/PUT requests.
- Use null-check assertions in client request builders.
When it happens
Trigger: A POST/PUT to the server-config endpoint with an empty body, null body, or a JSON literal 'null' that deserializes to a null ServerConfig.
Common situations: The caller sent an empty request body; the Content-Type was not set to application/json causing Spring to pass null; or the body was explicitly set to null in the client.
Related errors
- ServerConfig.Key cannot be blank
- 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/0189e6a44650fa13.
Report an issue: GitHub.