flowable/flowable-engine · error · ActivitiObjectNotFoundException

Process instance doesn't exist

Error message

Process instance ${processInstanceId} doesn't exist

What it means

When a processInstanceId is provided to createAttachment, the command loads the execution and throws ActivitiObjectNotFoundException with ProcessInstance.class if no such execution exists. The attachment cannot be linked to a non-existent process instance.

Solutions

  1. Verify existence with runtimeService.createProcessInstanceQuery().processInstanceId(id).singleResult() before attaching
  2. Correct the processInstanceId (don't confuse it with the business key)
  3. Attach using the historic instance or store the reference elsewhere if the runtime instance is gone

Example fix

// before
taskService.createAttachment("text", null, procInstId, "n", "d", stream);
// after
if (runtimeService.createProcessInstanceQuery().processInstanceId(procInstId).count() > 0) {
    taskService.createAttachment("text", null, procInstId, "n", "d", stream);
}
Defensive patterns

Strategy: validation

Validate before calling

boolean exists = processInstanceId == null || runtimeService.createProcessInstanceQuery().processInstanceId(processInstanceId).count() > 0;

Try / catch

try { taskService.createAttachment(...); } catch (ActivitiObjectNotFoundException e) { log.warn("Process instance {} no longer running", processInstanceId); }

Prevention

When it happens

Trigger: taskService.createAttachment(type, taskId, processInstanceId, ...) with a processInstanceId that was deleted, never existed, or belongs to another database.

Common situations: Attaching to a process instance after it completed and its runtime data was removed; environment mismatch; wrong variable passed (e.g. business key instead of instance id).

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


AI-assisted analysis of flowable/flowable-engine@d6d39ce1c6 (2026-09-11). Data as JSON: /api/errors/42e5cfd7cf38f686. Report an issue: GitHub.

Appendix: source

Thrown at modules/flowable5-engine/src/main/java/org/activiti/engine/impl/cmd/CreateAttachmentCmd.java:129

    private void verifyParameters(CommandContext commandContext) {
        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("It is not allowed to add an attachment to a suspended task");
            }
        }

        if (processInstanceId != null) {
            ExecutionEntity execution = commandContext.getExecutionEntityManager().findExecutionById(processInstanceId);

            if (execution == null) {
                throw new ActivitiObjectNotFoundException("Process instance " + processInstanceId + " doesn't exist", ProcessInstance.class);
            }

            if (execution.isSuspended()) {
                throw new ActivitiException("It is not allowed to add an attachment to a suspended process instance");
            }
        }
    }

}

View on GitHub (pinned to d6d39ce1c6)