flowable/flowable-engine · error · FlowableObjectNotFoundException

Process instance doesn't exist

Error message

Process instance  doesn't exist

What it means

CreateAttachmentCmd.verifyExecutionParameters resolves the processInstanceId as an ExecutionEntity; when no execution exists with that id it throws FlowableObjectNotFoundException with ProcessInstance.class. Attachments must reference an existing process instance.

Solutions

  1. Validate with runtimeService.createProcessInstanceQuery().processInstanceId(id).singleResult() before creating the attachment.
  2. If the instance already finished, store the attachment externally or in history rather than via createAttachment.
  3. Ensure you pass a runtime process instance id, not a caseInstanceId or historic id.

Example fix

// before
taskService.createAttachment(null, taskId, processInstanceId, name, desc, url);
// after
ProcessInstance pi = runtimeService.createProcessInstanceQuery().processInstanceId(processInstanceId).singleResult();
if (pi == null) {
    throw new IllegalArgumentException("No running process instance " + processInstanceId);
}
taskService.createAttachment(null, taskId, processInstanceId, name, desc, url);
Defensive patterns

Strategy: validation

Validate before calling

ProcessInstance pi = runtimeService.createProcessInstanceQuery().processInstanceId(processInstanceId).singleResult();
if (pi == null) {
    throw new IllegalArgumentException("No running process instance: " + processInstanceId);
}

Try / catch

try {
    taskService.createAttachment(null, taskId, pid, name, desc, url);
} catch (FlowableObjectNotFoundException e) {
    log.warn("Process instance not running: {}", pid);
}

Prevention

When it happens

Trigger: Calling TaskService.createAttachment with a processInstanceId that matches no execution in ACT_RU_EXECUTION (wrong id, instance already ended and removed, id from a different engine/database).

Common situations: Passing a historic process instance id after the runtime row was deleted on completion; passing a case instance id instead of a process instance id; environment mismatch (id from another deployment).

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/5d897f3671cec4c9. Report an issue: GitHub.

Appendix: source

Thrown at modules/flowable-engine/src/main/java/org/flowable/engine/impl/cmd/CreateAttachmentCmd.java:157

        ProcessEngineConfigurationImpl processEngineConfiguration = CommandContextUtil.getProcessEngineConfiguration(commandContext);
        TaskEntity 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("It is not allowed to add an attachment to a suspended " + task);
        }

        return task;
    }

    protected ExecutionEntity verifyExecutionParameters(CommandContext commandContext) {
        ExecutionEntity execution = CommandContextUtil.getExecutionEntityManager(commandContext).findById(processInstanceId);

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

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

        return execution;
    }

}

View on GitHub (pinned to d6d39ce1c6)