{"record":{"id":"d5f0dfcf80325489","repo":"apolloconfig/apollo","slug":"comment-item-s-key-or-value-should-be-blank","errorCode":null,"errorMessage":"Comment item's key or value should be blank.","messagePattern":"Comment item's key or value should be blank\\.","errorType":"exception","errorClass":"BadRequestException","httpStatus":400,"severity":"error","filePath":"apollo-adminservice/src/main/java/com/ctrip/framework/apollo/adminservice/controller/ItemController.java","lineNumber":108,"sourceCode":"            + \") for this namespace has been reached. Current item count is \" + itemCount + \".\");\n      }\n    }\n\n    entity = itemService.save(entity);\n    dto = BeanUtils.transform(ItemDTO.class, entity);\n    commitService.createCommit(appId, clusterName, namespaceName,\n        new ConfigChangeContentBuilder().createItem(entity).build(),\n        dto.getDataChangeLastModifiedBy());\n\n    return dto;\n  }\n\n  @PostMapping(\"/apps/{appId}/clusters/{clusterName}/namespaces/{namespaceName}/comment_items\")\n  public ItemDTO createComment(@PathVariable(\"appId\") String appId,\n      @PathVariable(\"clusterName\") String clusterName,\n      @PathVariable(\"namespaceName\") String namespaceName, @RequestBody ItemDTO dto) {\n    if (!StringUtils.isBlank(dto.getKey()) || !StringUtils.isBlank(dto.getValue())) {\n      throw new BadRequestException(\"Comment item's key or value should be blank.\");\n    }\n    if (StringUtils.isBlank(dto.getComment())) {\n      throw new BadRequestException(\"Comment item's comment should not be blank.\");\n    }\n\n    // check if comment existed\n    List<Item> allItems = itemService.findItemsWithOrdered(appId, clusterName, namespaceName);\n    for (Item item : allItems) {\n      if (StringUtils.isBlank(item.getKey()) && StringUtils.isBlank(item.getValue())\n          && Objects.equals(item.getComment(), dto.getComment())) {\n        return BeanUtils.transform(ItemDTO.class, item);\n      }\n    }\n\n    Item entity = BeanUtils.transform(Item.class, dto);\n    entity = itemService.saveComment(entity);\n\n    return BeanUtils.transform(ItemDTO.class, entity);","sourceCodeStart":90,"sourceCodeEnd":126,"githubUrl":"https://github.com/apolloconfig/apollo/blob/d95fc18d112589efc09ddcbe1507047584d55251/apollo-adminservice/src/main/java/com/ctrip/framework/apollo/adminservice/controller/ItemController.java#L90-L126","documentation":"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.","triggerScenarios":"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\"}.","commonSituations":"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.","solutions":["Ensure the request body to /comment_items has empty (or omitted) key and value fields — only the comment field should carry content.","Use the correct endpoint: POST .../items for key-value items, POST .../comment_items for standalone comments.","Explicitly set key and value to empty strings in the DTO before calling the comment endpoint."],"exampleFix":"// before: sending key/value to the comment endpoint\nItemDTO dto = new ItemDTO();\ndto.setKey(\"timeout\");\ndto.setValue(\"30\");\ndto.setComment(\"deprecated setting\");\nopenApi.createCommentItem(appId, env, cluster, namespace, dto); // fails\n\n// after: comment items must have blank key and value\nItemDTO dto = new ItemDTO();\ndto.setKey(\"\");\ndto.setValue(\"\");\ndto.setComment(\"Section: timeout settings\");\nopenApi.createCommentItem(appId, env, cluster, namespace, dto);","handlingStrategy":"validation","validationCode":"// Ensure key and value are blank for comment items\nif (StringUtils.isNotBlank(dto.getKey()) || StringUtils.isNotBlank(dto.getValue())) {\n    dto.setKey(\"\");\n    dto.setValue(\"\");\n}\nopenApi.createCommentItem(appId, env, cluster, namespace, dto);","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Use the correct endpoint: /comment_items for comments, /items for key-value pairs.","Explicitly set key and value to empty strings before calling the comment endpoint.","Differentiate comment-item DTOs from regular item DTOs in client code."],"tags":["item","comment","validation","bad-request","apollo-adminservice"],"backgroundTag":null,"analyzedSha":"d95fc18d112589efc09ddcbe1507047584d55251","analyzedAt":"2026-08-14T04:00:05.477Z","schemaVersion":2},"datasetVersion":"2026-08-14T05:17:29.042Z"}