{"record":{"id":"526205257687df3e","repo":"apolloconfig/apollo","slug":"key-too-long-length-limit-s","errorCode":null,"errorMessage":"key too long. length limit:%s","messagePattern":"key too long\\. length limit:(.+?)","errorType":"exception","errorClass":"BadRequestException","httpStatus":400,"severity":"error","filePath":"apollo-biz/src/main/java/com/ctrip/framework/apollo/biz/service/ItemService.java","lineNumber":253,"sourceCode":"    }\n    return true;\n  }\n\n  private int getGrayNamespaceItemValueLengthLimit(Namespace grayNamespace,\n      int grayNamespaceLimit) {\n    Namespace parentNamespace = namespaceService.findParentNamespace(grayNamespace);\n    if (parentNamespace != null) {\n      int parentLimit = getItemValueLengthLimit(parentNamespace);\n      if (parentLimit > grayNamespaceLimit) {\n        return parentLimit;\n      }\n    }\n    return grayNamespaceLimit;\n  }\n\n  private boolean checkItemKeyLength(String key) {\n    if (!StringUtils.isEmpty(key) && key.length() > bizConfig.itemKeyLengthLimit()) {\n      throw new BadRequestException(\"key too long. length limit:\" + bizConfig.itemKeyLengthLimit());\n    }\n    return true;\n  }\n\n  private boolean checkItemType(int type) {\n    if (type < 0 || type > 3) {\n      throw new BadRequestException(\"type is invalid. type should be in [0, 3]. \");\n    }\n    return true;\n  }\n\n  private int getItemValueLengthLimit(Namespace namespace) {\n    Map<Long, Integer> namespaceValueLengthOverride = bizConfig.namespaceValueLengthLimitOverride();\n    if (namespaceValueLengthOverride != null\n        && namespaceValueLengthOverride.containsKey(namespace.getId())) {\n      return namespaceValueLengthOverride.get(namespace.getId());\n    }\n","sourceCodeStart":235,"sourceCodeEnd":271,"githubUrl":"https://github.com/apolloconfig/apollo/blob/d95fc18d112589efc09ddcbe1507047584d55251/apollo-biz/src/main/java/com/ctrip/framework/apollo/biz/service/ItemService.java#L235-L271","documentation":"A BadRequestException (HTTP 400) thrown from ItemService.checkItemKeyLength() when an item's key exceeds the configured length limit. The limit comes from bizConfig.itemKeyLengthLimit(), which reads the config key 'item.key.length.limit' with a default of 128 (DEFAULT_ITEM_KEY_LENGTH, minimum 5). The check fires for non-empty keys only — comment items with blank keys bypass this.","triggerScenarios":"ItemService.save() is called with a key whose length exceeds bizConfig.itemKeyLengthLimit(). The default ceiling is 128 characters. The check is applied in save() (not in update(), which only checks type and value length).","commonSituations":"Deeply nested or auto-generated key names that exceed 128 characters; a naming convention that produces very long hierarchical keys; the limit was lowered after long keys were already in use.","solutions":["Shorten the key name to be within the limit (default 128 characters).","Increase the limit via biz config key 'item.key.length.limit' (minimum 5).","Refactor the key naming scheme to use shorter, flatter identifiers."],"exampleFix":"// before: very long hierarchical key\nitem.setKey(\"service.payment.gateway.timeout.http.read.default\");\n\n// after: shorter key or increase limit\nitem.setKey(\"payment.gateway.readTimeout\");\n// or in System Settings: item.key.length.limit = 256","handlingStrategy":"validation","validationCode":"// Check key length against the configured limit before saving\nint limit = bizConfig.itemKeyLengthLimit(); // default 128\nif (!StringUtils.isEmpty(key) && key.length() > limit) {\n    throw new IllegalArgumentException(\"Key exceeds limit of \" + limit);\n}\nitem.setKey(key);\nitemService.save(item);","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Validate key length client-side against the configured limit (default 128) before sending.","Use short, flat key naming conventions rather than deeply hierarchical paths.","Increase item.key.length.limit in biz config if longer keys are genuinely needed."],"tags":["item","key-length","validation","limit","biz-config","bad-request","apollo-biz"],"backgroundTag":null,"analyzedSha":"d95fc18d112589efc09ddcbe1507047584d55251","analyzedAt":"2026-08-14T04:00:05.477Z","schemaVersion":2},"datasetVersion":"2026-08-14T05:17:29.042Z"}