flowable/flowable-engine · error · FlowableObjectNotFoundException
Cannot find task with id {taskId}
Error message
Cannot find task with id {taskId} What it means
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.
Source
Thrown at modules/flowable-engine/src/main/java/org/flowable/engine/impl/cmd/AddCommentCmd.java:65
}
public AddCommentCmd(String taskId, String processInstanceId, String type, String message) {
this.taskId = taskId;
this.processInstanceId = processInstanceId;
this.type = type;
this.message = message;
}
@Override
public Comment execute(CommandContext commandContext) {
ProcessEngineConfigurationImpl processEngineConfiguration = CommandContextUtil.getProcessEngineConfiguration(commandContext);
TaskEntity task = null;
// Validate task
if (taskId != null) {
task = processEngineConfiguration.getTaskServiceConfiguration().getTaskService().getTask(taskId);
if (task == null) {
throw new FlowableObjectNotFoundException("Cannot find task with id " + taskId, Task.class);
}
if (task.isSuspended()) {
throw new FlowableException("Cannot add a comment to a suspended " + task);
}
}
ExecutionEntity execution = null;
if (processInstanceId != null) {
execution = processEngineConfiguration.getExecutionEntityManager().findById(processInstanceId);
if (execution == null) {
throw new FlowableObjectNotFoundException("execution " + processInstanceId + " doesn't exist", Execution.class);
}
if (execution.isSuspended()) {
throw new FlowableException("Cannot add a comment to a suspended " + execution);
}View on GitHub (pinned to d6d39ce1c6)
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.
Example fix
// before
taskService.addComment(taskId, processInstanceId, "done");
// after
Task t = taskService.createTaskQuery().taskId(taskId).singleResult();
if (t != null) {
taskService.addComment(taskId, processInstanceId, "done");
} else {
taskService.addComment(null, processInstanceId, "done");
} Defensive patterns
Strategy: validation
Validate before calling
if (taskId != null
&& taskService.createTaskQuery().taskId(taskId).singleResult() == null) {
throw new IllegalArgumentException("Unknown task: " + taskId);
} Try / catch
try {
taskService.addComment(taskId, processInstanceId, msg);
} catch (FlowableObjectNotFoundException e) {
// fall back to process-instance-level comment
taskService.addComment(null, processInstanceId, msg);
} Prevention
- Verify task existence before commenting.
- Respect addComment's parameter order (taskId first).
- For completed tasks, comment at the process-instance level instead.
When it happens
Trigger: taskService.addComment(taskId, processInstanceId, message) with a nonexistent, completed-and-purged, or cross-schema taskId.
Common situations: 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.
Understand the failure class
Background: "Not found" and "does not exist" errors: why "Task not found", "No such folder", and "Can't find" fire when a lookup comes back empty — this error's family across 14 libraries.
Related errors
- Cannot resume task with id '
- Cannot find task with id ${taskId}
- task ${taskId} doesn't exist
- Cannot find task with id {taskId}
- Cannot add a comment to a suspended {task}
AI-assisted analysis of flowable/flowable-engine@d6d39ce1c6 (2026-09-11).
Data as JSON: /api/errors/7822bbbf8579cff2.
Report an issue: GitHub.