{"record":{"id":"ee91db0a7e673d2e","repo":"apolloconfig/apollo","slug":"serverconfig-key-cannot-be-blank","errorCode":null,"errorMessage":"ServerConfig.Key cannot be blank","messagePattern":"ServerConfig\\.Key cannot be blank","errorType":"validation","errorClass":"BadRequestException","httpStatus":400,"severity":"error","filePath":"apollo-portal/src/main/java/com/ctrip/framework/apollo/openapi/v1/controller/PortalManagementController.java","lineNumber":919,"sourceCode":"        && !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    }\n  }\n\n  private Date parseAuditDate(String value) {","sourceCodeStart":901,"sourceCodeEnd":937,"githubUrl":"https://github.com/apolloconfig/apollo/blob/d95fc18d112589efc09ddcbe1507047584d55251/apollo-portal/src/main/java/com/ctrip/framework/apollo/openapi/v1/controller/PortalManagementController.java#L901-L937","documentation":"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.","triggerScenarios":"A server-config create/update request with a JSON body where the key field is missing, null, empty string, or contains only whitespace.","commonSituations":"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.","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."],"exampleFix":"// before\n{\"key\":\"\",\"value\":\"30\"}\n\n// after\n{\"key\":\"timeout.seconds\",\"value\":\"30\"}","handlingStrategy":"validation","validationCode":"// Validate key is non-blank before sending\nif (!org.springframework.util.StringUtils.hasText(serverConfig.getKey())) {\n  throw new IllegalArgumentException(\"ServerConfig key must not be blank\");\n}","typeGuard":"function hasNonBlankKey(body: { key?: string }): boolean {\n  return typeof body.key === 'string' && body.key.trim().length > 0;\n}","tryCatchPattern":null,"preventionTips":["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."],"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"}