{"record":{"id":"0189e6a44650fa13","repo":"apolloconfig/apollo","slug":"serverconfig-can-not-be-null","errorCode":null,"errorMessage":"ServerConfig can not be null","messagePattern":"ServerConfig can not be null","errorType":"validation","errorClass":"BadRequestException","httpStatus":400,"severity":"error","filePath":"apollo-portal/src/main/java/com/ctrip/framework/apollo/openapi/v1/controller/PortalManagementController.java","lineNumber":916,"sourceCode":"\n  private void validateConflictAction(String conflictAction) {\n    if (!CONFLICT_ACTION_COVER.equals(conflictAction)\n        && !CONFLICT_ACTION_IGNORE.equals(conflictAction)) {\n      throw new BadRequestException(\"ConflictAction is incorrect.\");\n    }\n  }\n\n  private String resolveConflictAction(String conflictAction) {\n    if (StringUtils.isEmpty(conflictAction)) {\n      return CONFLICT_ACTION_IGNORE;\n    }\n    validateConflictAction(conflictAction);\n    return conflictAction;\n  }\n\n  private void validateServerConfig(ServerConfig serverConfig) {\n    if (serverConfig == null) {\n      throw new BadRequestException(\"ServerConfig can not be null\");\n    }\n    if (!org.springframework.util.StringUtils.hasText(serverConfig.getKey())) {\n      throw new BadRequestException(\"ServerConfig.Key cannot be blank\");\n    }\n    if (!org.springframework.util.StringUtils.hasText(serverConfig.getValue())) {\n      throw new BadRequestException(\"ServerConfig.Value cannot be blank\");\n    }\n  }\n\n  private Date parseConsumerExpires(String expires) {\n    if (!org.springframework.util.StringUtils.hasText(expires)) {\n      return DEFAULT_EXPIRES;\n    }\n    try {\n      return new SimpleDateFormat(\"yyyyMMddHHmmss\").parse(expires);\n    } catch (ParseException e) {\n      throw new BadRequestException(\"Invalid expires format: %s\", expires);\n    }","sourceCodeStart":898,"sourceCodeEnd":934,"githubUrl":"https://github.com/apolloconfig/apollo/blob/d95fc18d112589efc09ddcbe1507047584d55251/apollo-portal/src/main/java/com/ctrip/framework/apollo/openapi/v1/controller/PortalManagementController.java#L898-L934","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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."],"exampleFix":"// before\nPOST /server-config\n(empty body)\n\n// after\nPOST /server-config\n{\"key\":\"timeout\",\"value\":\"30\"}","handlingStrategy":"validation","validationCode":"// Validate ServerConfig is non-null before sending\nif (serverConfig == null) {\n  throw new IllegalArgumentException(\"ServerConfig body must not be null\");\n}","typeGuard":"function isNonNullServerConfig(body: unknown): body is { key: string; value: string } {\n  return typeof body === 'object' && body !== null;\n}","tryCatchPattern":null,"preventionTips":["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."],"tags":["validation","openapi","bad-request","server-config","apollo-portal"],"backgroundTag":null,"analyzedSha":"d95fc18d112589efc09ddcbe1507047584d55251","analyzedAt":"2026-08-14T04:00:05.477Z","schemaVersion":2},"datasetVersion":"2026-08-14T05:17:29.042Z"}