{"record":{"id":"419597a801943c8d","repo":"apolloconfig/apollo","slug":"comment-item-s-comment-should-not-be-blank","errorCode":null,"errorMessage":"Comment item's comment should not be blank.","messagePattern":"Comment item's comment should not 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":111,"sourceCode":"\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);\n  }\n\n","sourceCodeStart":93,"sourceCodeEnd":129,"githubUrl":"https://github.com/apolloconfig/apollo/blob/d95fc18d112589efc09ddcbe1507047584d55251/apollo-adminservice/src/main/java/com/ctrip/framework/apollo/adminservice/controller/ItemController.java#L93-L129","documentation":"A BadRequestException (HTTP 400) thrown from ItemController.createComment() (POST .../comment_items) when the comment field is blank. After validating that key and value are blank (error [5]), this check ensures the comment itself has content — a comment item with no comment text is meaningless. The validation is: StringUtils.isBlank(dto.getComment()).","triggerScenarios":"POST .../comment_items with a JSON body where the comment field is null, empty, or whitespace-only, e.g. {\"key\":\"\",\"value\":\"\",\"comment\":\"\"} or {\"key\":\"\",\"value\":\"\",\"comment\":\"   \"}.","commonSituations":"Client sends an empty comment by mistake; a form submission where the comment field was left blank; programmatic creation where the comment variable was uninitialized.","solutions":["Provide a non-blank comment string in the request body.","Add client-side validation to require the comment field before calling the endpoint.","Skip the API call entirely if the comment is blank, since the server will reject it."],"exampleFix":"// before: empty comment\nItemDTO dto = new ItemDTO();\ndto.setKey(\"\");\ndto.setValue(\"\");\ndto.setComment(\"\"); // blank -> rejected\nopenApi.createCommentItem(appId, env, cluster, namespace, dto);\n\n// after: validate before calling\nif (StringUtils.isNotBlank(commentText)) {\n    dto.setComment(commentText);\n    openApi.createCommentItem(appId, env, cluster, namespace, dto);\n}","handlingStrategy":"validation","validationCode":"// Validate comment is non-blank before calling\nif (StringUtils.isBlank(dto.getComment())) {\n    throw new IllegalArgumentException(\"Comment text is required\");\n}\nopenApi.createCommentItem(appId, env, cluster, namespace, dto);","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Add client-side validation requiring the comment field before calling the endpoint.","Skip the API call if the comment is blank rather than letting the server reject it.","Initialize the comment field from validated user input."],"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"}