{"record":{"id":"838aa8282be33c60","repo":"apolloconfig/apollo","slug":"value-too-long-length-limit-s","errorCode":null,"errorMessage":"value too long. length limit:%s","messagePattern":"value 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":234,"sourceCode":"\n    auditService.audit(Item.class.getSimpleName(), managedItem.getId(), Audit.OP.UPDATE,\n        managedItem.getDataChangeLastModifiedBy());\n\n    return managedItem;\n  }\n\n  private boolean checkItemValueLength(long namespaceId, String value) {\n    Namespace currentNamespace = namespaceService.findOne(namespaceId);\n    int limit = getItemValueLengthLimit(currentNamespace);\n    if (currentNamespace != null) {\n      Matcher m = clusterPattern.matcher(currentNamespace.getClusterName());\n      boolean isGray = m.matches();\n      if (isGray) {\n        limit = getGrayNamespaceItemValueLengthLimit(currentNamespace, limit);\n      }\n    }\n    if (!StringUtils.isEmpty(value) && value.length() > limit) {\n      throw new BadRequestException(\"value too long. length limit:\" + limit);\n    }\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()) {","sourceCodeStart":216,"sourceCodeEnd":252,"githubUrl":"https://github.com/apolloconfig/apollo/blob/d95fc18d112589efc09ddcbe1507047584d55251/apollo-biz/src/main/java/com/ctrip/framework/apollo/biz/service/ItemService.java#L216-L252","documentation":"A BadRequestException (HTTP 400) thrown from ItemService.checkItemValueLength() when an item's value exceeds the configured length limit. The limit is determined by getItemValueLengthLimit(): per-namespace override > per-appId override > global default (DEFAULT_ITEM_VALUE_LENGTH = 20000). For gray-release namespaces (cluster name matching pattern [0-9]{14}-[a-zA-Z0-9]{16}), the limit may be raised to the parent namespace's limit if it is larger.","triggerScenarios":"ItemService.save() or update() is called with a value whose length exceeds the resolved limit. The check fires for non-empty values only. Config keys involved: item.value.length.limit (default 20000), appid.value.length.limit.override (JSON map), namespace.value.length.limit.override (JSON map).","commonSituations":"Storing a large blob, certificate, or long JSON string as a config value that exceeds 20000 characters; the global limit was lowered via config after large values were already present; a migration importing values that exceed the limit.","solutions":["Shorten the value to be within the limit, or store large data externally and reference it by URL/key in Apollo.","Increase the limit via biz config key 'item.value.length.limit' (minimum 5).","Set a per-appId override via 'appid.value.length.limit.override' (JSON: {\"appId\": limit}) or per-namespace via 'namespace.value.length.limit.override' (JSON: {\"namespaceId\": limit}).","For gray namespaces, ensure the parent namespace has a sufficiently large limit so the gray limit inherits it."],"exampleFix":"// before: storing a huge value directly\nitem.setValue(hugeCertificatePem); // > 20000 chars -> rejected\n\n// after option 1: reference externally\nitem.setValue(\"s3://config-bucket/cert.pem\");\n\n// after option 2: increase limit in biz config\n// System Settings: item.value.length.limit = 50000","handlingStrategy":"validation","validationCode":"// Check value length against the configured limit before saving\nint limit = bizConfig.itemValueLengthLimit(); // default 20000\nif (!StringUtils.isEmpty(value) && value.length() > limit) {\n    // truncate, externalize, or increase limit before proceeding\n    throw new IllegalArgumentException(\"Value exceeds limit of \" + limit);\n}\nitem.setValue(value);\nitemService.save(item);","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Validate value length client-side against the configured limit before sending.","Store large blobs externally and reference them by URL in Apollo.","Set appropriate per-appId or per-namespace value-length overrides if specific namespaces need larger values.","Monitor biz config for changes to item.value.length.limit."],"tags":["item","value-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"}