flowable/flowable-engine · error · FlowableObjectNotFoundException
Cannot find task with id
Error message
Cannot find task with id
What it means
After the null check, NeedsActiveTaskCmd.execute() looks up the task via the task service. If no task exists with the given id it throws FlowableObjectNotFoundException 'Cannot find task with id <taskId>' with Task.class as the type, indicating the referenced task entity does not exist (or is not visible) in the persistent store.
Source
Thrown at modules/flowable-cmmn-engine/src/main/java/org/flowable/cmmn/engine/impl/cmd/NeedsActiveTaskCmd.java:53
protected String taskId;
public NeedsActiveTaskCmd(String taskId) {
this.taskId = taskId;
}
@Override
public T execute(CommandContext commandContext) {
if (taskId == null) {
throw new FlowableIllegalArgumentException("taskId is null");
}
CmmnEngineConfiguration cmmnEngineConfiguration = CommandContextUtil.getCmmnEngineConfiguration(commandContext);
TaskEntity task = cmmnEngineConfiguration.getTaskServiceConfiguration().getTaskService().getTask(taskId);
if (task == null) {
throw new FlowableObjectNotFoundException("Cannot find task with id " + taskId, Task.class);
}
if (task.isSuspended()) {
throw new FlowableException(getSuspendedTaskExceptionPrefix() + " a suspended " + task);
}
return execute(commandContext, task);
}
/**
* Subclasses must implement in this method their normal command logic. The provided task is ensured to be active.
*/
protected abstract T execute(CommandContext commandContext, TaskEntity task);
/**
* Subclasses can override this method to provide a customized exception message that will be thrown when the task is suspended.
*/
protected String getSuspendedTaskExceptionPrefix() {View on GitHub (pinned to d6d39ce1c6)
Solutions
- Verify the task exists first: taskService.createTaskQuery().taskId(id).singleResult() != null
- Use freshly fetched task ids from taskService.createTaskQuery() results instead of cached values
- Catch FlowableObjectNotFoundException to handle missing tasks gracefully
Example fix
// before
taskService.complete(oldTaskId); // task already deleted
// after
Task task = taskService.createTaskQuery().taskId(taskId).singleResult();
if (task != null) { taskService.complete(task.getId()); } Defensive patterns
Strategy: validation
Validate before calling
Task t = taskService.createTaskQuery().taskId(taskId).singleResult();
if (t == null) throw new IllegalArgumentException("No such task: " + taskId); Try / catch
try { taskService.complete(taskId); } catch (FlowableObjectNotFoundException e) { log.warn("Task {} no longer exists", taskId); } Prevention
- Refresh task references before acting (tasks can be deleted concurrently)
- Don't persist task ids across transactions/restarts; re-query instead
- Verify you're on the same engine/datasource that owns the task
When it happens
Trigger: Executing a task command with an id that was never persisted, was deleted (e.g. cascading delete after case instance termination), or belongs to a different database/tenant scope.
Common situations: Stale task ids cached from a previous run; task deleted by another user/process concurrently; id copied from the BPMN engine (process tasks) while operating on the CMMN engine; test/prod data mixing.
Understand the failure class
Background: Record Not Found Errors: "not found", RecordNotFound, and "was not found" — what they mean and how to fix them — this error's family across 28 libraries.
Related errors
- task ${taskId} doesn't exist
- task ${taskId} doesn't exist
- task ${taskId} doesn't exist
- No External Worker job found for id: ${externalJobId}
- taskId is null
AI-assisted analysis of flowable/flowable-engine@d6d39ce1c6 (2026-09-11).
Data as JSON: /api/errors/aa553995f9843fb3.
Report an issue: GitHub.