{"record":{"id":"6a6882d85153dd74","repo":"flowable/flowable-engine","slug":"no-process-instance-found-for-id-processins-6a6882","errorCode":null,"errorMessage":"No process instance found for id = '\" + processInstanceId + \"'.","messagePattern":"No process instance found for id = '\" \\+ processInstanceId \\+ \"'\\.","errorType":"exception","errorClass":"ActivitiObjectNotFoundException","httpStatus":null,"severity":"error","filePath":"modules/flowable5-engine/src/main/java/org/activiti/engine/impl/cmd/SetProcessDefinitionVersionCmd.java","lineNumber":80,"sourceCode":"        }\n        if (processDefinitionVersion == null) {\n            throw new ActivitiIllegalArgumentException(\"The process definition version is mandatory, but 'null' has been provided.\");\n        }\n        if (processDefinitionVersion < 1) {\n            throw new ActivitiIllegalArgumentException(\"The process definition version must be positive, but '\" + processDefinitionVersion + \"' has been provided.\");\n        }\n        this.processInstanceId = processInstanceId;\n        this.processDefinitionVersion = processDefinitionVersion;\n    }\n\n    @Override\n    public Void execute(CommandContext commandContext) {\n        // check that the new process definition is just another version of the same\n        // process definition that the process instance is using\n        ExecutionEntityManager executionManager = commandContext.getExecutionEntityManager();\n        ExecutionEntity processInstance = executionManager.findExecutionById(processInstanceId);\n        if (processInstance == null) {\n            throw new ActivitiObjectNotFoundException(\"No process instance found for id = '\" + processInstanceId + \"'.\", ProcessInstance.class);\n        } else if (!processInstance.isProcessInstanceType()) {\n            throw new ActivitiIllegalArgumentException(\n                    \"A process instance id is required, but the provided id \" +\n                            \"'\" + processInstanceId + \"' \" +\n                            \"points to a child execution of process instance \" +\n                            \"'\" + processInstance.getProcessInstanceId() + \"'. \" +\n                            \"Please invoke the \" + getClass().getSimpleName() + \" with a root execution id.\");\n        }\n        ProcessDefinitionImpl currentProcessDefinitionImpl = processInstance.getProcessDefinition();\n\n        DeploymentManager deploymentCache = commandContext\n                .getProcessEngineConfiguration()\n                .getDeploymentManager();\n        ProcessDefinition currentProcessDefinition = null;\n        if (currentProcessDefinitionImpl instanceof ProcessDefinitionEntity) {\n            currentProcessDefinition = (ProcessDefinitionEntity) currentProcessDefinitionImpl;\n        } else {\n            currentProcessDefinition = deploymentCache.findDeployedProcessDefinitionById(currentProcessDefinitionImpl.getId());","sourceCodeStart":62,"sourceCodeEnd":98,"githubUrl":"https://github.com/flowable/flowable-engine/blob/d6d39ce1c69ff244f2d9dc6af756a9b95e865586/modules/flowable5-engine/src/main/java/org/activiti/engine/impl/cmd/SetProcessDefinitionVersionCmd.java#L62-L98","documentation":"execute() looks up the execution via ExecutionEntityManager.findExecutionById(processInstanceId) and throws ActivitiObjectNotFoundException (typed with ProcessInstance.class) when no execution with that id exists. The id passed to the command does not correspond to any execution in the engine's persistence layer.","triggerScenarios":"runtimeService.setProcessDefinitionVersion(pid, v) with a pid that was never created, was deleted (runtimeService.deleteProcessInstance), or belongs to a different engine/database.","commonSituations":"Stale ids cached after the instance completed or was cancelled; pointing at a historic (ended) instance where the runtime row is gone; multi-tenant/multi-engine setups querying the wrong data source.","solutions":["Verify the id exists before migrating: runtimeService.createProcessInstanceQuery().processInstanceId(pid).singleResult() != null.","If the instance already ended, use history APIs (HistoricProcessInstanceQuery) instead of runtime migration.","Confirm the id comes from the same engine instance/database schema the command runs against.","Catch ActivitiObjectNotFoundException around the call and surface a user-friendly 'process instance not found' message."],"exampleFix":"// before\nruntimeService.setProcessDefinitionVersion(storedPid, newVersion);\n// after\nif (runtimeService.createProcessInstanceQuery().processInstanceId(storedPid).count() == 0) {\n    throw new IllegalStateException(\"Process instance \" + storedPid + \" no longer exists\");\n}\nruntimeService.setProcessDefinitionVersion(storedPid, newVersion);","handlingStrategy":"try-catch","validationCode":"boolean exists = runtimeService.createProcessInstanceQuery().processInstanceId(pid).count() > 0;","typeGuard":"boolean isRunningInstance(RuntimeService rs, String pid) {\n    return pid != null && rs.createProcessInstanceQuery().processInstanceId(pid).count() > 0;\n}","tryCatchPattern":"try {\n    runtimeService.setProcessDefinitionVersion(pid, version);\n} catch (org.activiti.engine.ActivitiObjectNotFoundException e) {\n    // instance does not exist / already ended\n}","preventionTips":["Check ProcessInstanceQuery before runtime mutations","Do not cache process instance ids across long time spans","Verify engine/datasource consistency in multi-engine setups"],"tags":["java","flowable","entity-not-found","process-instance"],"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"}