flowable/flowable-engine · error · ActivitiObjectNotFoundException
execution ${processInstanceId} doesn't exist
Error message
execution ${processInstanceId} doesn't exist What it means
AddCommentCmd.execute validates an optional processInstanceId by looking up the execution and throws ActivitiObjectNotFoundException when no execution with that id exists. A comment can reference a process instance, but the referenced instance must exist at comment time.
Source
Thrown at modules/flowable5-engine/src/main/java/org/activiti/engine/impl/cmd/AddCommentCmd.java:72
// 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());
}
}
String userId = Authentication.getAuthenticatedUserId();
CommentEntity comment = new CommentEntity();
comment.setUserId(userId);
comment.setType((type == null) ? CommentEntity.TYPE_COMMENT : type);
comment.setTime(commandContext.getProcessEngineConfiguration().getClock().getCurrentTime());
comment.setTaskId(taskId);
comment.setProcessInstanceId(processInstanceId);
comment.setAction(Event.ACTION_ADD_COMMENT);
String eventMessage = message.replaceAll("\\s+", " ");
if (eventMessage.length() > 163) {View on GitHub (pinned to d6d39ce1c6)
Solutions
- Check existence first: runtimeService.createProcessInstanceQuery().processInstanceId(pid).count() > 0.
- Use the runtime ProcessInstance.getId(), not the business key.
- If the instance is finished, add the comment to the related historical data via HistoryService instead of the runtime comment API.
- Confirm arguments are not swapped: addComment(taskId, processInstanceId, message).
Example fix
// before
taskService.addComment(null, instanceId, "note");
// after
if (runtimeService.createProcessInstanceQuery().processInstanceId(instanceId).count() > 0) {
taskService.addComment(null, instanceId, "note");
} Defensive patterns
Strategy: validation
Validate before calling
boolean exists = runtimeService.createProcessInstanceQuery()
.processInstanceId(processInstanceId).count() > 0;
if (!exists) { throw new IllegalStateException("Process instance " + processInstanceId + " not running"); } Try / catch
try {
taskService.addComment(null, processInstanceId, message);
} catch (ActivitiObjectNotFoundException e) {
if (e.getMessage().startsWith("execution ")) {
logger.warn("Instance {} finished; store comment via history", processInstanceId);
} else { throw e; }
} Prevention
- Validate the instance id against a runtime query first
- Do not pass business keys where runtime instance ids are expected
- Route comments for finished instances to history services
When it happens
Trigger: Calling TaskService.addComment(taskId, processInstanceId, message) or addComment(null, processInstanceId, message) with a processInstanceId that does not exist, already ended, or is mistyped.
Common situations: Commenting against a completed instance whose runtime execution row is gone (use history instead); id taken from a business key rather than the runtime id; environment/database mismatch.
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
- execution {processInstanceId} doesn't exist
- Cannot find processInstance for id '${executionId}'.
- Cannot find task with id ${taskId}
- Cannot find process definition with id
- The process instance with id '{processInstanceId}' could not
AI-assisted analysis of flowable/flowable-engine@d6d39ce1c6 (2026-09-11).
Data as JSON: /api/errors/61c84adc0262e9da.
Report an issue: GitHub.