{"record":{"id":"7822bbbf8579cff2","repo":"flowable/flowable-engine","slug":"cannot-find-task-with-id-taskid-7822bb","errorCode":null,"errorMessage":"Cannot find task with id {taskId}","messagePattern":"Cannot find task with id (.+?)","errorType":"exception","errorClass":"FlowableObjectNotFoundException","httpStatus":null,"severity":"error","filePath":"modules/flowable-engine/src/main/java/org/flowable/engine/impl/cmd/AddCommentCmd.java","lineNumber":65,"sourceCode":"    }\n\n    public AddCommentCmd(String taskId, String processInstanceId, String type, String message) {\n        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        ProcessEngineConfigurationImpl processEngineConfiguration = CommandContextUtil.getProcessEngineConfiguration(commandContext);\n        TaskEntity task = null;\n        // Validate task\n        if (taskId != null) {\n            task = processEngineConfiguration.getTaskServiceConfiguration().getTaskService().getTask(taskId);\n\n            if (task == null) {\n                throw new FlowableObjectNotFoundException(\"Cannot find task with id \" + taskId, Task.class);\n            }\n\n            if (task.isSuspended()) {\n                throw new FlowableException(\"Cannot add a comment to a suspended \" + task);\n            }\n        }\n\n        ExecutionEntity execution = null;\n        if (processInstanceId != null) {\n            execution = processEngineConfiguration.getExecutionEntityManager().findById(processInstanceId);\n\n            if (execution == null) {\n                throw new FlowableObjectNotFoundException(\"execution \" + processInstanceId + \" doesn't exist\", Execution.class);\n            }\n\n            if (execution.isSuspended()) {\n                throw new FlowableException(\"Cannot add a comment to a suspended \" + execution);\n            }","sourceCodeStart":47,"sourceCodeEnd":83,"githubUrl":"https://github.com/flowable/flowable-engine/blob/d6d39ce1c69ff244f2d9dc6af756a9b95e865586/modules/flowable-engine/src/main/java/org/flowable/engine/impl/cmd/AddCommentCmd.java#L47-L83","documentation":"FlowableObjectNotFoundException thrown by AddCommentCmd.execute when a taskId was supplied to taskService.addComment(...) but no task with that id exists. Comments are attached to the task entity, so the command validates the task before writing.","triggerScenarios":"taskService.addComment(taskId, processInstanceId, message) with a nonexistent, completed-and-purged, or cross-schema taskId.","commonSituations":"Adding comments from an external UI after the task completed; stale task ids stored client-side; wrong tenant/schema datasource; passing processInstanceId into the taskId parameter by mistake.","solutions":["Confirm the task exists: taskService.createTaskQuery().taskId(taskId).singleResult() != null before adding the comment.","Check the argument order of addComment(taskId, processInstanceId, message) — do not pass the processInstanceId in the taskId slot.","If the task is completed, add comments to the process instance instead (null taskId, processInstanceId set).","Verify both API calls target the same database/schema/tenant."],"exampleFix":"// before\ntaskService.addComment(taskId, processInstanceId, \"done\");\n// after\nTask t = taskService.createTaskQuery().taskId(taskId).singleResult();\nif (t != null) {\n    taskService.addComment(taskId, processInstanceId, \"done\");\n} else {\n    taskService.addComment(null, processInstanceId, \"done\");\n}","handlingStrategy":"validation","validationCode":"if (taskId != null\n        && taskService.createTaskQuery().taskId(taskId).singleResult() == null) {\n    throw new IllegalArgumentException(\"Unknown task: \" + taskId);\n}","typeGuard":null,"tryCatchPattern":"try {\n    taskService.addComment(taskId, processInstanceId, msg);\n} catch (FlowableObjectNotFoundException e) {\n    // fall back to process-instance-level comment\n    taskService.addComment(null, processInstanceId, msg);\n}","preventionTips":["Verify task existence before commenting.","Respect addComment's parameter order (taskId first).","For completed tasks, comment at the process-instance level instead."],"tags":["flowable","task","comment","not-found"],"backgroundTag":"entity-not-found","analyzedSha":"d6d39ce1c69ff244f2d9dc6af756a9b95e865586","analyzedAt":"2026-09-11T06:41:19.413Z","contentChangedAt":"2026-09-11T06:41:19.413Z","schemaVersion":2},"datasetVersion":"2026-09-14T11:17:12.474Z"}