apolloconfig/apollo · error · BadRequestException

key too long. length limit:%s

Error message

key too long. length limit:%s

What it means

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.

Source

Thrown at apollo-biz/src/main/java/com/ctrip/framework/apollo/biz/service/ItemService.java:253

    }
    return true;
  }

  private int getGrayNamespaceItemValueLengthLimit(Namespace grayNamespace,
      int grayNamespaceLimit) {
    Namespace parentNamespace = namespaceService.findParentNamespace(grayNamespace);
    if (parentNamespace != null) {
      int parentLimit = getItemValueLengthLimit(parentNamespace);
      if (parentLimit > grayNamespaceLimit) {
        return parentLimit;
      }
    }
    return grayNamespaceLimit;
  }

  private boolean checkItemKeyLength(String key) {
    if (!StringUtils.isEmpty(key) && key.length() > bizConfig.itemKeyLengthLimit()) {
      throw new BadRequestException("key too long. length limit:" + bizConfig.itemKeyLengthLimit());
    }
    return true;
  }

  private boolean checkItemType(int type) {
    if (type < 0 || type > 3) {
      throw new BadRequestException("type is invalid. type should be in [0, 3]. ");
    }
    return true;
  }

  private int getItemValueLengthLimit(Namespace namespace) {
    Map<Long, Integer> namespaceValueLengthOverride = bizConfig.namespaceValueLengthLimitOverride();
    if (namespaceValueLengthOverride != null
        && namespaceValueLengthOverride.containsKey(namespace.getId())) {
      return namespaceValueLengthOverride.get(namespace.getId());
    }

View on GitHub (pinned to d95fc18d11)

Solutions

  1. Shorten the key name to be within the limit (default 128 characters).
  2. Increase the limit via biz config key 'item.key.length.limit' (minimum 5).
  3. Refactor the key naming scheme to use shorter, flatter identifiers.

Example fix

// before: very long hierarchical key
item.setKey("service.payment.gateway.timeout.http.read.default");

// after: shorter key or increase limit
item.setKey("payment.gateway.readTimeout");
// or in System Settings: item.key.length.limit = 256
Defensive patterns

Strategy: validation

Validate before calling

// Check key length against the configured limit before saving
int limit = bizConfig.itemKeyLengthLimit(); // default 128
if (!StringUtils.isEmpty(key) && key.length() > limit) {
    throw new IllegalArgumentException("Key exceeds limit of " + limit);
}
item.setKey(key);
itemService.save(item);

Prevention

When it happens

Trigger: 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).

Common situations: 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.

Related errors


AI-assisted analysis of apolloconfig/apollo@d95fc18d11 (2026-08-14). Data as JSON: /api/errors/526205257687df3e. Report an issue: GitHub.