{"record":{"id":"9589bd9acc315de8","repo":"flowable/flowable-engine","slug":"cannot-find-process-instance-with-id-processinst-9589bd","errorCode":null,"errorMessage":"Cannot find process instance with id ${processInstanceId}","messagePattern":"Cannot find process instance with id (.+?)","errorType":"exception","errorClass":"ActivitiObjectNotFoundException","httpStatus":null,"severity":"error","filePath":"modules/flowable5-engine/src/main/java/org/activiti/engine/impl/cmd/DeleteIdentityLinkForProcessInstanceCmd.java","lineNumber":66,"sourceCode":"        if (processInstanceId == null) {\n            throw new ActivitiIllegalArgumentException(\"processInstanceId is null\");\n        }\n\n        if (type == null) {\n            throw new ActivitiIllegalArgumentException(\"type is required when deleting a process identity link\");\n        }\n\n        if (userId == null && groupId == null) {\n            throw new ActivitiIllegalArgumentException(\"userId and groupId cannot both be null\");\n        }\n    }\n\n    @Override\n    public Void execute(CommandContext commandContext) {\n        ExecutionEntity processInstance = commandContext.getExecutionEntityManager().findExecutionById(processInstanceId);\n\n        if (processInstance == null) {\n            throw new ActivitiObjectNotFoundException(\"Cannot find process instance with id \" + processInstanceId, ExecutionEntity.class);\n        }\n\n        processInstance.deleteIdentityLink(userId, groupId, type);\n\n        commandContext.getHistoryManager().createProcessInstanceIdentityLinkComment(processInstanceId, userId, groupId, type, false);\n\n        return null;\n    }\n\n}\n","sourceCodeStart":48,"sourceCodeEnd":77,"githubUrl":"https://github.com/flowable/flowable-engine/blob/d6d39ce1c69ff244f2d9dc6af756a9b95e865586/modules/flowable5-engine/src/main/java/org/activiti/engine/impl/cmd/DeleteIdentityLinkForProcessInstanceCmd.java#L48-L77","documentation":"The command looked up processInstanceId via the execution entity manager and found no execution with that id, so it throws ActivitiObjectNotFoundException with ExecutionEntity as the missing-object class. Identity links exist only on live runtime executions; a stale or invalid id cannot be targeted.","triggerScenarios":"Calling deleteProcessInstanceIdentityLink with a processInstanceId that matches no execution: instance already completed or aborted (history-only), wrong id type (taskId/jobId), or an id from a different engine/database.","commonSituations":"Cleanup jobs deleting links after the process already ended; subprocess vs. process-instance id mismatches; multi-engine/multi-tenant setups where the id belongs to another engine's datasource.","solutions":["Verify the instance exists and is running first: runtimeService.createProcessInstanceQuery().processInstanceId(pid).singleResult() != null.","If the instance is finished, operate on history or skip deletion — runtime links are gone with the execution.","Confirm the id is a process instance/execution id, not a task or job id.","Check you are connected to the engine/database that owns the id (correct datasource and engine version)."],"exampleFix":"// before\nruntimeService.deleteProcessInstanceIdentityLink(pid, userId, groupId, type);\n// after\nProcessInstance pi = runtimeService.createProcessInstanceQuery().processInstanceId(pid).singleResult();\nif (pi != null) {\n    runtimeService.deleteProcessInstanceIdentityLink(pid, userId, groupId, type);\n}","handlingStrategy":"try-catch","validationCode":"ProcessInstance pi = runtimeService.createProcessInstanceQuery().processInstanceId(pid).singleResult();\nif (pi == null) {\n    return; // instance already ended or id invalid; nothing to unlink\n}","typeGuard":"boolean isRunningProcessInstance(RuntimeService rs, String pid) {\n    return pid != null && rs.createProcessInstanceQuery().processInstanceId(pid).count() > 0;\n}","tryCatchPattern":"try {\n    runtimeService.deleteProcessInstanceIdentityLink(pid, userId, groupId, type);\n} catch (ActivitiObjectNotFoundException e) {\n    if (ExecutionEntity.class.equals(e.getObjectClass())) {\n        LOGGER.warn(\"Process instance {} no longer exists; skipping identity link cleanup\", pid);\n        return;\n    }\n    throw e;\n}","preventionTips":["Check existence with a ProcessInstanceQuery before mutating runtime links.","Treat completed/aborted instances as no-op for link cleanup in maintenance jobs.","Verify ids refer to the same engine instance and datasource.","Do not confuse taskId with processInstanceId."],"tags":["not-found","process-instance","identity-link","stale-reference"],"backgroundTag":"record-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"}