apolloconfig/apollo · error · BadRequestException

Comment item's key or value should be blank.

Error message

Comment item's key or value should be blank.

What it means

A BadRequestException (HTTP 400) thrown from ItemController.createComment() (POST .../comment_items) when the comment item's key or value is not blank. A comment item in Apollo is a special item type that holds only a comment (no key-value pair); both key and value must be empty strings. The validation is: if dto.getKey() is not blank OR dto.getValue() is not blank, the request is rejected.

Source

Thrown at apollo-adminservice/src/main/java/com/ctrip/framework/apollo/adminservice/controller/ItemController.java:108

            + ") for this namespace has been reached. Current item count is " + itemCount + ".");
      }
    }

    entity = itemService.save(entity);
    dto = BeanUtils.transform(ItemDTO.class, entity);
    commitService.createCommit(appId, clusterName, namespaceName,
        new ConfigChangeContentBuilder().createItem(entity).build(),
        dto.getDataChangeLastModifiedBy());

    return dto;
  }

  @PostMapping("/apps/{appId}/clusters/{clusterName}/namespaces/{namespaceName}/comment_items")
  public ItemDTO createComment(@PathVariable("appId") String appId,
      @PathVariable("clusterName") String clusterName,
      @PathVariable("namespaceName") String namespaceName, @RequestBody ItemDTO dto) {
    if (!StringUtils.isBlank(dto.getKey()) || !StringUtils.isBlank(dto.getValue())) {
      throw new BadRequestException("Comment item's key or value should be blank.");
    }
    if (StringUtils.isBlank(dto.getComment())) {
      throw new BadRequestException("Comment item's comment should not be blank.");
    }

    // check if comment existed
    List<Item> allItems = itemService.findItemsWithOrdered(appId, clusterName, namespaceName);
    for (Item item : allItems) {
      if (StringUtils.isBlank(item.getKey()) && StringUtils.isBlank(item.getValue())
          && Objects.equals(item.getComment(), dto.getComment())) {
        return BeanUtils.transform(ItemDTO.class, item);
      }
    }

    Item entity = BeanUtils.transform(Item.class, dto);
    entity = itemService.saveComment(entity);

    return BeanUtils.transform(ItemDTO.class, entity);

View on GitHub (pinned to d95fc18d11)

Solutions

  1. Ensure the request body to /comment_items has empty (or omitted) key and value fields — only the comment field should carry content.
  2. Use the correct endpoint: POST .../items for key-value items, POST .../comment_items for standalone comments.
  3. Explicitly set key and value to empty strings in the DTO before calling the comment endpoint.

Example fix

// before: sending key/value to the comment endpoint
ItemDTO dto = new ItemDTO();
dto.setKey("timeout");
dto.setValue("30");
dto.setComment("deprecated setting");
openApi.createCommentItem(appId, env, cluster, namespace, dto); // fails

// after: comment items must have blank key and value
ItemDTO dto = new ItemDTO();
dto.setKey("");
dto.setValue("");
dto.setComment("Section: timeout settings");
openApi.createCommentItem(appId, env, cluster, namespace, dto);
Defensive patterns

Strategy: validation

Validate before calling

// Ensure key and value are blank for comment items
if (StringUtils.isNotBlank(dto.getKey()) || StringUtils.isNotBlank(dto.getValue())) {
    dto.setKey("");
    dto.setValue("");
}
openApi.createCommentItem(appId, env, cluster, namespace, dto);

Prevention

When it happens

Trigger: POST .../comment_items with a JSON body where key or value contains non-whitespace text, e.g. {"key":"timeout","value":"30","comment":"note"}. The endpoint expects {"key":"","value":"","comment":"actual comment text"}.

Common situations: Client mistakenly sends a regular config item to the comment endpoint; confusion between the create-item and create-comment-item APIs; a serialization bug that populates key/value fields that should be omitted for comments.

Related errors


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