{"record":{"id":"5d897f3671cec4c9","repo":"flowable/flowable-engine","slug":"process-instance-doesn-t-exist","errorCode":null,"errorMessage":"Process instance  doesn't exist","messagePattern":"Process instance  doesn't exist","errorType":"exception","errorClass":"FlowableObjectNotFoundException","httpStatus":null,"severity":"error","filePath":"modules/flowable-engine/src/main/java/org/flowable/engine/impl/cmd/CreateAttachmentCmd.java","lineNumber":157,"sourceCode":"        ProcessEngineConfigurationImpl processEngineConfiguration = CommandContextUtil.getProcessEngineConfiguration(commandContext);\n        TaskEntity task = processEngineConfiguration.getTaskServiceConfiguration().getTaskService().getTask(taskId);\n\n        if (task == null) {\n            throw new FlowableObjectNotFoundException(\"Cannot find task with id \" + taskId, Task.class);\n        }\n\n        if (task.isSuspended()) {\n            throw new FlowableException(\"It is not allowed to add an attachment to a suspended \" + task);\n        }\n\n        return task;\n    }\n\n    protected ExecutionEntity verifyExecutionParameters(CommandContext commandContext) {\n        ExecutionEntity execution = CommandContextUtil.getExecutionEntityManager(commandContext).findById(processInstanceId);\n\n        if (execution == null) {\n            throw new FlowableObjectNotFoundException(\"Process instance \" + processInstanceId + \" doesn't exist\", ProcessInstance.class);\n        }\n\n        if (execution.isSuspended()) {\n            throw new FlowableException(\"It is not allowed to add an attachment to a suspended \" + execution);\n        }\n\n        return execution;\n    }\n\n}\n","sourceCodeStart":139,"sourceCodeEnd":168,"githubUrl":"https://github.com/flowable/flowable-engine/blob/d6d39ce1c69ff244f2d9dc6af756a9b95e865586/modules/flowable-engine/src/main/java/org/flowable/engine/impl/cmd/CreateAttachmentCmd.java#L139-L168","documentation":"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.","triggerScenarios":"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).","commonSituations":"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).","solutions":["Validate with runtimeService.createProcessInstanceQuery().processInstanceId(id).singleResult() before creating the attachment.","If the instance already finished, store the attachment externally or in history rather than via createAttachment.","Ensure you pass a runtime process instance id, not a caseInstanceId or historic id."],"exampleFix":"// before\ntaskService.createAttachment(null, taskId, processInstanceId, name, desc, url);\n// after\nProcessInstance pi = runtimeService.createProcessInstanceQuery().processInstanceId(processInstanceId).singleResult();\nif (pi == null) {\n    throw new IllegalArgumentException(\"No running process instance \" + processInstanceId);\n}\ntaskService.createAttachment(null, taskId, processInstanceId, name, desc, url);","handlingStrategy":"validation","validationCode":"ProcessInstance pi = runtimeService.createProcessInstanceQuery().processInstanceId(processInstanceId).singleResult();\nif (pi == null) {\n    throw new IllegalArgumentException(\"No running process instance: \" + processInstanceId);\n}","typeGuard":null,"tryCatchPattern":"try {\n    taskService.createAttachment(null, taskId, pid, name, desc, url);\n} catch (FlowableObjectNotFoundException e) {\n    log.warn(\"Process instance not running: {}\", pid);\n}","preventionTips":["Pass execution/task-derived process instance ids, not historic or case ids","Query runtime state before writes that depend on a live instance","Differentiate runtime vs history ids clearly in your data model"],"tags":["flowable","process-instance","attachment"],"backgroundTag":"entity-not-found","analyzedSha":"d6d39ce1c69ff244f2d9dc6af756a9b95e865586","analyzedAt":"2026-09-11T06:41:19.413Z","contentChangedAt":"2026-09-11T06:41:19.413Z","schemaVersion":2},"datasetVersion":"2026-09-18T11:17:12.947Z"}