{"record":{"id":"80e7e6ba0dfdd42b","repo":"flowable/flowable-engine","slug":"comment-with-id-commentid-doesn-t-exists","errorCode":null,"errorMessage":"Comment with id '${commentId}' doesn't exists.","messagePattern":"Comment with id '(.+?)' doesn't exists\\.","errorType":"exception","errorClass":"ActivitiObjectNotFoundException","httpStatus":null,"severity":"warning","filePath":"modules/flowable5-engine/src/main/java/org/activiti/engine/impl/cmd/DeleteCommentCmd.java","lineNumber":49,"sourceCode":"    protected String taskId;\n    protected String processInstanceId;\n    protected String commentId;\n\n    public DeleteCommentCmd(String taskId, String processInstanceId, String commentId) {\n        this.taskId = taskId;\n        this.processInstanceId = processInstanceId;\n        this.commentId = commentId;\n    }\n\n    @Override\n    public Void execute(CommandContext commandContext) {\n        CommentEntityManager commentManager = commandContext.getCommentEntityManager();\n\n        if (commentId != null) {\n            // Delete for an individual comment\n            Comment comment = commentManager.findComment(commentId);\n            if (comment == null) {\n                throw new ActivitiObjectNotFoundException(\"Comment with id '\" + commentId + \"' doesn't exists.\", Comment.class);\n            }\n            commentManager.delete((CommentEntity) comment);\n\n        } else {\n            // Delete all comments on a task of process\n            ArrayList<Comment> comments = new ArrayList<>();\n            if (processInstanceId != null) {\n                comments.addAll(commentManager.findCommentsByProcessInstanceId(processInstanceId));\n            }\n            if (taskId != null) {\n                comments.addAll(commentManager.findCommentsByTaskId(taskId));\n            }\n\n            for (Comment comment : comments) {\n                commentManager.delete((CommentEntity) comment);\n            }\n        }\n        return null;","sourceCodeStart":31,"sourceCodeEnd":67,"githubUrl":"https://github.com/flowable/flowable-engine/blob/d6d39ce1c69ff244f2d9dc6af756a9b95e865586/modules/flowable5-engine/src/main/java/org/activiti/engine/impl/cmd/DeleteCommentCmd.java#L31-L67","documentation":"DeleteCommentCmd deletes a single comment by id, and throws ActivitiObjectNotFoundException with Comment.class when findComment returns null. The id is syntactically fine but no comment row with it exists.","triggerScenarios":"taskService.deleteComment(commentId) (or the cmd directly) with an id already deleted, never created, or from another database.","commonSituations":"Double-delete in a UI (comment removed by another user first); stale client cache listing comments; wrong-environment ids in test scripts.","solutions":["Verify the comment exists (taskService.getTaskComments / getProcessInstanceComments) before deleting","Handle the missing comment as a no-op: catch ActivitiObjectNotFoundException and log","Correct the commentId source (refresh from the server instead of a cached list)"],"exampleFix":"// before\ntaskService.deleteComment(commentId);\n// after\ntry {\n    taskService.deleteComment(commentId);\n} catch (ActivitiObjectNotFoundException e) {\n    // comment already gone; treat as deleted\n}","handlingStrategy":"try-catch","validationCode":"boolean exists = taskService.getProcessInstanceComments(procInstId).stream().anyMatch(c -> c.getId().equals(commentId));","typeGuard":null,"tryCatchPattern":"try { taskService.deleteComment(commentId); } catch (ActivitiObjectNotFoundException e) { /* already deleted — treat as success */ }","preventionTips":["Refresh comment lists before delete operations","Make delete idempotent by catching not-found","Avoid stale client-side comment caches"],"tags":["not-found","comment","delete"],"backgroundTag":"record-not-found","analyzedSha":"d6d39ce1c69ff244f2d9dc6af756a9b95e865586","analyzedAt":"2026-09-11T06:41:19.413Z","contentChangedAt":"2026-09-11T06:41:19.413Z","schemaVersion":2},"datasetVersion":"2026-09-18T11:17:12.947Z"}