flowable/flowable-engine · error · ActivitiObjectNotFoundException
Cannot find task with id ${taskId}
Error message
Cannot find task with id ${taskId} What it means
AddCommentCmd.execute validates an optional taskId by looking it up via the task entity manager and throws ActivitiObjectNotFoundException when no task with that id exists. Comments can be attached to a task, a process instance, or neither, but a supplied task id must be valid.
Source
Thrown at modules/flowable5-engine/src/main/java/org/activiti/engine/impl/cmd/AddCommentCmd.java:60
this.message = message;
}
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) {
// Validate task
if (taskId != null) {
TaskEntity task = commandContext.getTaskEntityManager().findTaskById(taskId);
if (task == null) {
throw new ActivitiObjectNotFoundException("Cannot find task with id " + taskId, Task.class);
}
if (task.isSuspended()) {
throw new ActivitiException(getSuspendedTaskException());
}
}
if (processInstanceId != null) {
ExecutionEntity execution = commandContext.getExecutionEntityManager().findExecutionById(processInstanceId);
if (execution == null) {
throw new ActivitiObjectNotFoundException("execution " + processInstanceId + " doesn't exist", Execution.class);
}
if (execution.isSuspended()) {
throw new ActivitiException(getSuspendedExceptionMessage());
}
}View on GitHub (pinned to d6d39ce1c6)
Solutions
- Verify the task exists before commenting: taskService.createTaskQuery().taskId(id).singleResult() != null.
- Use the Task.getId() from a live Task object rather than a hand-typed or stale id.
- If the task may already be completed, look it up in history (HistoryService) and attach the comment there, or add the comment with only the processInstanceId.
- Check that you are not swapping the argument order of taskId and processInstanceId in addComment(taskId, processInstanceId, message).
Example fix
// before
taskService.addComment(taskId, procId, "reviewed");
// after
if (taskService.createTaskQuery().taskId(taskId).count() > 0) {
taskService.addComment(taskId, procId, "reviewed");
} Defensive patterns
Strategy: validation
Validate before calling
Task task = taskService.createTaskQuery().taskId(taskId).singleResult();
if (task == null) { throw new IllegalStateException("Task " + taskId + " not found"); } Try / catch
try {
taskService.addComment(taskId, processInstanceId, message);
} catch (ActivitiObjectNotFoundException e) {
if (e.getMessage().startsWith("Cannot find task with id")) {
logger.warn("Task {} gone; posting comment on process instead", taskId);
taskService.addComment(null, processInstanceId, message);
} else { throw e; }
} Prevention
- Look up the task immediately before commenting
- Do not cache task ids across transactions — runtime tasks are removed on completion
- Do not swap taskId and processInstanceId arguments
- Use history API for finished tasks
When it happens
Trigger: Calling TaskService.addComment(null-as-taskId variant is skipped) with a taskId string that does not match any task: stale/finished task id, typo, or id from another datasource.
Common situations: Commenting on a task after it was completed and its runtime data removed; copying ids between test/production databases; passing a process instance id where a task id is expected.
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 find task with id {taskId}
- execution ${processInstanceId} doesn't exist
- Cannot resume task with id '
- Cannot find task with id ${taskId}
- task ${taskId} doesn't exist
AI-assisted analysis of flowable/flowable-engine@d6d39ce1c6 (2026-09-11).
Data as JSON: /api/errors/f0c3bfc276c62822.
Report an issue: GitHub.