apolloconfig/apollo · error · BadRequestException

Comment length should not exceed %s characters

Error message

Comment length should not exceed %s characters

What it means

Thrown by ItemController.checkCommentLength when the comment field on an OpenItemDTO exceeds 256 characters (ITEM_COMMENT_MAX_LENGTH). Apollo enforces a maximum comment length to prevent oversized audit-trail entries and database bloat. Maps to HTTP 400 BadRequestException.

Source

Thrown at apollo-portal/src/main/java/com/ctrip/framework/apollo/openapi/v1/controller/ItemController.java:271

    }
    String resolvedOperator = resolveOperator(operator, payloadOperator);
    item.setDataChangeLastModifiedBy(resolvedOperator);
    if (createIfNotExists && StringUtils.isBlank(item.getDataChangeCreatedBy())) {
      item.setDataChangeCreatedBy(resolvedOperator);
    }

    if (createIfNotExists) {
      this.itemOpenApiService.createOrUpdateItem(appId, env, clusterName, namespaceName, item,
          resolvedOperator);
    } else {
      this.itemOpenApiService.updateItem(appId, env, clusterName, namespaceName, item,
          resolvedOperator);
    }
  }

  private void checkCommentLength(String comment) {
    if (!StringUtils.isEmpty(comment) && comment.length() > ITEM_COMMENT_MAX_LENGTH) {
      throw new BadRequestException("Comment length should not exceed %s characters",
          ITEM_COMMENT_MAX_LENGTH);
    }
  }

  private String resolveOperator(String queryOperator, String payloadOperator) {
    String authType = UserIdentityContextHolder.getAuthType();
    if (UserIdentityConstants.USER.equals(authType)
        || UserIdentityConstants.USER_TOKEN.equals(authType)) {
      UserInfo loginUser = userInfoHolder.getUser();
      if (loginUser == null || StringUtils.isBlank(loginUser.getUserId())) {
        throw new BadRequestException("Current user not found");
      }
      return loginUser.getUserId();
    }

    if (UserIdentityConstants.CONSUMER.equals(authType)) {
      String operator = StringUtils.isBlank(queryOperator) ? payloadOperator : queryOperator;
      RequestPrecondition.checkArguments(!StringUtils.isContainEmpty(operator),

View on GitHub (pinned to d95fc18d11)

Solutions

  1. Truncate the comment to 256 characters before sending: comment = comment.length() > 256 ? comment.substring(0, 256) : comment.
  2. Shorten the comment to a concise summary and move detailed information to a linked external system (Jira ticket, commit hash).
  3. Validate the comment length client-side and reject/warn before the API call.

Example fix

// before — full commit message used as comment, may exceed 256
item.setComment(commitMessage);
client.post("/items", item); // throws if commitMessage > 256 chars

// after — truncate to max length
String comment = commitMessage;
if (comment != null && comment.length() > 256) {
    comment = comment.substring(0, 256);
}
item.setComment(comment);
client.post("/items", item);
Defensive patterns

Strategy: validation

Validate before calling

// Truncate comment to 256 characters before setting it on the item
private static final int MAX_COMMENT_LENGTH = 256;
String safeComment = (comment == null || comment.length() <= MAX_COMMENT_LENGTH)
    ? comment
    : comment.substring(0, MAX_COMMENT_LENGTH);
item.setComment(safeComment);

Type guard

private static boolean isValidCommentLength(String comment) {
    return comment == null || comment.length() <= 256;
}

Prevention

When it happens

Trigger: POST or PUT /openapi/v1/envs/{env}/apps/{appId}/clusters/{clusterName}/namespaces/{namespaceName}/items with a JSON body containing a "comment" field longer than 256 characters.

Common situations: A CI/CD pipeline auto-generates a comment from a build description or commit message that exceeds 256 characters. A migration script copies verbose descriptions into the comment field. Debug or diagnostic information is accidentally placed in the comment field.

Related errors


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