{"record":{"id":"8a1d6cbc3a4233db","repo":"apolloconfig/apollo","slug":"comment-length-should-not-exceed-s-characters","errorCode":null,"errorMessage":"Comment length should not exceed %s characters","messagePattern":"Comment length should not exceed (.+?) characters","errorType":"exception","errorClass":"BadRequestException","httpStatus":400,"severity":"error","filePath":"apollo-portal/src/main/java/com/ctrip/framework/apollo/openapi/v1/controller/ItemController.java","lineNumber":271,"sourceCode":"    }\n    String resolvedOperator = resolveOperator(operator, payloadOperator);\n    item.setDataChangeLastModifiedBy(resolvedOperator);\n    if (createIfNotExists && StringUtils.isBlank(item.getDataChangeCreatedBy())) {\n      item.setDataChangeCreatedBy(resolvedOperator);\n    }\n\n    if (createIfNotExists) {\n      this.itemOpenApiService.createOrUpdateItem(appId, env, clusterName, namespaceName, item,\n          resolvedOperator);\n    } else {\n      this.itemOpenApiService.updateItem(appId, env, clusterName, namespaceName, item,\n          resolvedOperator);\n    }\n  }\n\n  private void checkCommentLength(String comment) {\n    if (!StringUtils.isEmpty(comment) && comment.length() > ITEM_COMMENT_MAX_LENGTH) {\n      throw new BadRequestException(\"Comment length should not exceed %s characters\",\n          ITEM_COMMENT_MAX_LENGTH);\n    }\n  }\n\n  private String resolveOperator(String queryOperator, String payloadOperator) {\n    String authType = UserIdentityContextHolder.getAuthType();\n    if (UserIdentityConstants.USER.equals(authType)\n        || UserIdentityConstants.USER_TOKEN.equals(authType)) {\n      UserInfo loginUser = userInfoHolder.getUser();\n      if (loginUser == null || StringUtils.isBlank(loginUser.getUserId())) {\n        throw new BadRequestException(\"Current user not found\");\n      }\n      return loginUser.getUserId();\n    }\n\n    if (UserIdentityConstants.CONSUMER.equals(authType)) {\n      String operator = StringUtils.isBlank(queryOperator) ? payloadOperator : queryOperator;\n      RequestPrecondition.checkArguments(!StringUtils.isContainEmpty(operator),","sourceCodeStart":253,"sourceCodeEnd":289,"githubUrl":"https://github.com/apolloconfig/apollo/blob/d95fc18d112589efc09ddcbe1507047584d55251/apollo-portal/src/main/java/com/ctrip/framework/apollo/openapi/v1/controller/ItemController.java#L253-L289","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Truncate the comment to 256 characters before sending: comment = comment.length() > 256 ? comment.substring(0, 256) : comment.","Shorten the comment to a concise summary and move detailed information to a linked external system (Jira ticket, commit hash).","Validate the comment length client-side and reject/warn before the API call."],"exampleFix":"// before — full commit message used as comment, may exceed 256\nitem.setComment(commitMessage);\nclient.post(\"/items\", item); // throws if commitMessage > 256 chars\n\n// after — truncate to max length\nString comment = commitMessage;\nif (comment != null && comment.length() > 256) {\n    comment = comment.substring(0, 256);\n}\nitem.setComment(comment);\nclient.post(\"/items\", item);","handlingStrategy":"validation","validationCode":"// Truncate comment to 256 characters before setting it on the item\nprivate static final int MAX_COMMENT_LENGTH = 256;\nString safeComment = (comment == null || comment.length() <= MAX_COMMENT_LENGTH)\n    ? comment\n    : comment.substring(0, MAX_COMMENT_LENGTH);\nitem.setComment(safeComment);","typeGuard":"private static boolean isValidCommentLength(String comment) {\n    return comment == null || comment.length() <= 256;\n}","tryCatchPattern":null,"preventionTips":["Always truncate or validate comment length client-side before the API call.","Use concise, structured comments (e.g. 'Deploy v1.2.3 - JIRA-456') rather than free-form text.","In CI/CD pipelines, derive comments from short identifiers like build numbers or commit hashes."],"tags":["validation","openapi","item","bad-request","input-validation","http-400","length-limit"],"backgroundTag":null,"analyzedSha":"d95fc18d112589efc09ddcbe1507047584d55251","analyzedAt":"2026-08-14T04:00:05.477Z","schemaVersion":2},"datasetVersion":"2026-08-14T05:17:29.042Z"}