{"record":{"id":"c0de8a55f897ab9c","repo":"flowable/flowable-engine","slug":"cannot-add-a-comment-to-a-suspended-task-c0de8a","errorCode":null,"errorMessage":"Cannot add a comment to a suspended task","messagePattern":"Cannot add a comment to a suspended task","errorType":"exception","errorClass":"ActivitiException","httpStatus":null,"severity":"error","filePath":"modules/flowable5-engine/src/main/java/org/activiti/engine/impl/cmd/AddCommentCmd.java","lineNumber":64,"sourceCode":"        this.taskId = taskId;\n        this.processInstanceId = processInstanceId;\n        this.type = type;\n        this.message = message;\n    }\n\n    @Override\n    public Comment execute(CommandContext commandContext) {\n\n        // Validate task\n        if (taskId != null) {\n            TaskEntity task = commandContext.getTaskEntityManager().findTaskById(taskId);\n\n            if (task == null) {\n                throw new ActivitiObjectNotFoundException(\"Cannot find task with id \" + taskId, Task.class);\n            }\n\n            if (task.isSuspended()) {\n                throw new ActivitiException(getSuspendedTaskException());\n            }\n        }\n\n        if (processInstanceId != null) {\n            ExecutionEntity execution = commandContext.getExecutionEntityManager().findExecutionById(processInstanceId);\n\n            if (execution == null) {\n                throw new ActivitiObjectNotFoundException(\"execution \" + processInstanceId + \" doesn't exist\", Execution.class);\n            }\n\n            if (execution.isSuspended()) {\n                throw new ActivitiException(getSuspendedExceptionMessage());\n            }\n        }\n\n        String userId = Authentication.getAuthenticatedUserId();\n        CommentEntity comment = new CommentEntity();\n        comment.setUserId(userId);","sourceCodeStart":46,"sourceCodeEnd":82,"githubUrl":"https://github.com/flowable/flowable-engine/blob/d6d39ce1c69ff244f2d9dc6af756a9b95e865586/modules/flowable5-engine/src/main/java/org/activiti/engine/impl/cmd/AddCommentCmd.java#L46-L82","documentation":"AddCommentCmd.execute rejects adding a comment to a task whose isSuspended() is true, via getSuspendedTaskException(). While a task's process instance is suspended, state-changing operations like commenting are blocked by design.","triggerScenarios":"Calling TaskService.addComment(taskId, ...) (or createTaskComment) where the target task belongs to a suspended process instance — e.g. after suspendProcessInstanceById or a suspend defined on the process definition.","commonSituations":"Users of a UI try to add remarks while the workflow is administratively paused; batch jobs post comments to tasks during a suspension window; tests that suspend instances but keep writing comments.","solutions":["Activate the process instance first: runtimeService.activateProcessInstanceById(task.getProcessInstanceId()).","Check suspension before commenting: task.isSuspended() or the execution's suspension state, and defer/comment elsewhere.","Use the process-level API only after confirming the definition/instance is active via ProcessDefinitionQuery/ProcessInstanceQuery suspension state."],"exampleFix":"// before\ntaskService.addComment(taskId, null, \"note\");\n// after\nTask task = taskService.createTaskQuery().taskId(taskId).singleResult();\nif (task != null && !task.isSuspended()) {\n    taskService.addComment(taskId, null, \"note\");\n}","handlingStrategy":"validation","validationCode":"Task task = taskService.createTaskQuery().taskId(taskId).singleResult();\nif (task != null && task.isSuspended()) {\n    throw new IllegalStateException(\"Task \" + taskId + \" is suspended\");\n}","typeGuard":null,"tryCatchPattern":"try {\n    taskService.addComment(taskId, null, message);\n} catch (ActivitiException e) {\n    if (\"Cannot add a comment to a suspended task\".equals(e.getMessage())) {\n        logger.info(\"Deferring comment; task {} suspended\", taskId);\n    } else { throw e; }\n}","preventionTips":["Check Task.isSuspended() before mutating task-scoped data","Track suspension windows in the UI and disable comment input","Activate the process instance before resuming user actions"],"tags":["suspended-task","comment","invalid-state-transition","activiti"],"backgroundTag":"invalid-state-transition","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"}