{"record":{"id":"42e5cfd7cf38f686","repo":"flowable/flowable-engine","slug":"process-instance-processinstanceid-doesn-t-exis-42e5cf","errorCode":null,"errorMessage":"Process instance ${processInstanceId} doesn't exist","messagePattern":"Process instance (.+?) doesn't exist","errorType":"exception","errorClass":"ActivitiObjectNotFoundException","httpStatus":null,"severity":"error","filePath":"modules/flowable5-engine/src/main/java/org/activiti/engine/impl/cmd/CreateAttachmentCmd.java","lineNumber":129,"sourceCode":"\n    private void verifyParameters(CommandContext commandContext) {\n        if (taskId != null) {\n            TaskEntity task = commandContext.getTaskEntityManager().findTaskById(taskId);\n\n            if (task == null) {\n                throw new ActivitiObjectNotFoundException(\"Cannot find task with id \" + taskId, Task.class);\n            }\n\n            if (task.isSuspended()) {\n                throw new ActivitiException(\"It is not allowed to add an attachment to a suspended task\");\n            }\n        }\n\n        if (processInstanceId != null) {\n            ExecutionEntity execution = commandContext.getExecutionEntityManager().findExecutionById(processInstanceId);\n\n            if (execution == null) {\n                throw new ActivitiObjectNotFoundException(\"Process instance \" + processInstanceId + \" doesn't exist\", ProcessInstance.class);\n            }\n\n            if (execution.isSuspended()) {\n                throw new ActivitiException(\"It is not allowed to add an attachment to a suspended process instance\");\n            }\n        }\n    }\n\n}\n","sourceCodeStart":111,"sourceCodeEnd":139,"githubUrl":"https://github.com/flowable/flowable-engine/blob/d6d39ce1c69ff244f2d9dc6af756a9b95e865586/modules/flowable5-engine/src/main/java/org/activiti/engine/impl/cmd/CreateAttachmentCmd.java#L111-L139","documentation":"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.","triggerScenarios":"taskService.createAttachment(type, taskId, processInstanceId, ...) with a processInstanceId that was deleted, never existed, or belongs to another database.","commonSituations":"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).","solutions":["Verify existence with runtimeService.createProcessInstanceQuery().processInstanceId(id).singleResult() before attaching","Correct the processInstanceId (don't confuse it with the business key)","Attach using the historic instance or store the reference elsewhere if the runtime instance is gone"],"exampleFix":"// before\ntaskService.createAttachment(\"text\", null, procInstId, \"n\", \"d\", stream);\n// after\nif (runtimeService.createProcessInstanceQuery().processInstanceId(procInstId).count() > 0) {\n    taskService.createAttachment(\"text\", null, procInstId, \"n\", \"d\", stream);\n}","handlingStrategy":"validation","validationCode":"boolean exists = processInstanceId == null || runtimeService.createProcessInstanceQuery().processInstanceId(processInstanceId).count() > 0;","typeGuard":null,"tryCatchPattern":"try { taskService.createAttachment(...); } catch (ActivitiObjectNotFoundException e) { log.warn(\"Process instance {} no longer running\", processInstanceId); }","preventionTips":["Verify the instance is live before attaching","Don't confuse business keys with instance ids","Expect runtime rows to vanish after completion — use history API if needed"],"tags":["not-found","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"}