{"record":{"id":"7f17546d89c34f8b","repo":"flowable/flowable-engine","slug":"cannot-find-process-instance-with-id-processinst","errorCode":null,"errorMessage":"Cannot find process instance with id ${processInstanceId}","messagePattern":"Cannot find process instance with id (.+?)","errorType":"exception","errorClass":"FlowableObjectNotFoundException","httpStatus":null,"severity":"error","filePath":"modules/flowable-engine/src/main/java/org/flowable/engine/impl/cmd/DeleteIdentityLinkForProcessInstanceCmd.java","lineNumber":71,"sourceCode":"        if (processInstanceId == null) {\n            throw new FlowableIllegalArgumentException(\"processInstanceId is null\");\n        }\n\n        if (type == null) {\n            throw new FlowableIllegalArgumentException(\"type is required when deleting a process identity link\");\n        }\n\n        if (userId == null && groupId == null) {\n            throw new FlowableIllegalArgumentException(\"userId and groupId cannot both be null\");\n        }\n    }\n\n    @Override\n    public Void execute(CommandContext commandContext) {\n        ExecutionEntity processInstance = CommandContextUtil.getExecutionEntityManager(commandContext).findById(processInstanceId);\n\n        if (processInstance == null) {\n            throw new FlowableObjectNotFoundException(\"Cannot find process instance with id \" + processInstanceId, ExecutionEntity.class);\n        }\n\n        if (Flowable5Util.isFlowable5ProcessDefinitionId(commandContext, processInstance.getProcessDefinitionId())) {\n            Flowable5CompatibilityHandler compatibilityHandler = Flowable5Util.getFlowable5CompatibilityHandler();\n            compatibilityHandler.deleteIdentityLinkForProcessInstance(processInstanceId, userId, groupId, type);\n            return null;\n        }\n\n        IdentityLinkUtil.deleteProcessInstanceIdentityLinks(processInstance, userId, groupId, type);\n        CommandContextUtil.getHistoryManager(commandContext).createProcessInstanceIdentityLinkComment(processInstance, userId, groupId, type, false);\n\n        return null;\n    }\n\n}\n","sourceCodeStart":53,"sourceCodeEnd":87,"githubUrl":"https://github.com/flowable/flowable-engine/blob/d6d39ce1c69ff244f2d9dc6af756a9b95e865586/modules/flowable-engine/src/main/java/org/flowable/engine/impl/cmd/DeleteIdentityLinkForProcessInstanceCmd.java#L53-L87","documentation":"In execute(), DeleteIdentityLinkForProcessInstanceCmd loads the execution by processInstanceId. If no execution exists for that id, Flowable throws FlowableObjectNotFoundException referencing ExecutionEntity.class — the id is well-formed but no such process instance exists.","triggerScenarios":"Calling deleteProcessInstanceIdentityLink with an id of a process instance that already ended, was deleted, or never existed in this database/tenant.","commonSituations":"Operating on a stale id captured before the instance completed; pointing at another environment's database; ids from an in-memory/H2 test database not present in production.","solutions":["Confirm the instance is still running: runtimeService.createProcessInstanceQuery().processInstanceId(id).singleResult() before deleting links.","Re-resolve the id from a fresh query instead of a cached/stale value.","Catch FlowableObjectNotFoundException and treat it as idempotent success if the instance is already gone."],"exampleFix":"// before\nruntimeService.deleteProcessInstanceIdentityLink(piId, userId, groupId, type);\n// after\nProcessInstance pi = runtimeService.createProcessInstanceQuery().processInstanceId(piId).singleResult();\nif (pi != null) {\n    runtimeService.deleteProcessInstanceIdentityLink(piId, userId, groupId, type);\n}","handlingStrategy":"validation","validationCode":"ProcessInstance pi = runtimeService.createProcessInstanceQuery()\n        .processInstanceId(piId).singleResult();\nif (pi == null) {\n    // instance already ended or never existed; skip deletion\n    return;\n}","typeGuard":"boolean instanceRunning(RuntimeService rs, String piId) {\n    return piId != null && rs.createProcessInstanceQuery().processInstanceId(piId).count() > 0;\n}","tryCatchPattern":"try {\n    runtimeService.deleteProcessInstanceIdentityLink(piId, userId, groupId, type);\n} catch (FlowableObjectNotFoundException e) {\n    log.info(\"Process instance {} not found; treating delete as no-op\", piId);\n}","preventionTips":["Check the instance is still running before mutating its identity links.","Refresh stale ids captured before async completion or deletion of the instance.","Use the correct database/tenant; ids are not portable across environments."],"tags":["flowable","process-instance","not-found","execution"],"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-14T11:17:12.474Z"}