{"record":{"id":"7bee191c20d7cd2c","repo":"flowable/flowable-engine","slug":"cannot-find-processinstance-for-id-executionid","errorCode":null,"errorMessage":"Cannot find processInstance for id '${executionId}'.","messagePattern":"Cannot find processInstance for id '(.+?)'\\.","errorType":"exception","errorClass":"ActivitiObjectNotFoundException","httpStatus":null,"severity":"error","filePath":"modules/flowable5-engine/src/main/java/org/activiti/engine/impl/cmd/AbstractSetProcessInstanceStateCmd.java","lineNumber":54,"sourceCode":"public abstract class AbstractSetProcessInstanceStateCmd implements Command<Void> {\r\n\r\n    protected final String executionId;\r\n\r\n    public AbstractSetProcessInstanceStateCmd(String executionId) {\r\n        this.executionId = executionId;\r\n    }\r\n\r\n    @Override\r\n    public Void execute(CommandContext commandContext) {\r\n\r\n        if (executionId == null) {\r\n            throw new ActivitiIllegalArgumentException(\"ProcessInstanceId cannot be null.\");\r\n        }\r\n\r\n        ExecutionEntity executionEntity = commandContext.getExecutionEntityManager().findExecutionById(executionId);\r\n\r\n        if (executionEntity == null) {\r\n            throw new ActivitiObjectNotFoundException(\"Cannot find processInstance for id '\" + executionId + \"'.\", Execution.class);\r\n        }\r\n        if (!executionEntity.isProcessInstanceType()) {\r\n            throw new ActivitiException(\"Cannot set suspension state for execution '\" + executionId + \"': not a process instance.\");\r\n        }\r\n\r\n        SuspensionStateUtil.setSuspensionState(executionEntity, getNewState());\r\n\r\n        // All child executions are suspended\r\n        List<ExecutionEntity> childExecutions = commandContext.getExecutionEntityManager().findChildExecutionsByProcessInstanceId(executionId);\r\n        for (ExecutionEntity childExecution : childExecutions) {\r\n            if (!childExecution.getId().equals(executionId)) {\r\n                SuspensionStateUtil.setSuspensionState(childExecution, getNewState());\r\n            }\r\n        }\r\n\r\n        // All tasks are suspended\r\n        List<TaskEntity> tasks = commandContext.getTaskEntityManager().findTasksByProcessInstanceId(executionId);\r\n        for (TaskEntity taskEntity : tasks) {\r","sourceCodeStart":36,"sourceCodeEnd":72,"githubUrl":"https://github.com/flowable/flowable-engine/blob/d6d39ce1c69ff244f2d9dc6af756a9b95e865586/modules/flowable5-engine/src/main/java/org/activiti/engine/impl/cmd/AbstractSetProcessInstanceStateCmd.java#L36-L72","documentation":"AbstractSetProcessInstanceStateCmd.execute looks up the execution by id via the execution entity manager and throws ActivitiObjectNotFoundException when no execution with that id exists. The suspension state of a non-existent process instance cannot be changed.","triggerScenarios":"Calling RuntimeService.suspendProcessInstanceById(id)/activateProcessInstanceById(id) with an id that does not exist, was mistyped, or belongs to a process instance that already ended and was removed.","commonSituations":"Using a stale id from a previous run or another database/environment; confusing business key with instance id; the instance completed and was cleaned up before the suspend call.","solutions":["Confirm the id exists: runtimeService.createProcessInstanceQuery().processInstanceId(id).singleResult() != null before suspending/activating.","Use the id returned by ProcessInstance.getId() from the API, not the business key.","Re-check which database/environment the engine connects to; stale ids from another environment throw here.","If the instance may have finished, handle the not-found case gracefully instead of failing."],"exampleFix":"// before\nruntimeService.activateProcessInstanceById(procId);\n// after\nProcessInstance pi = runtimeService.createProcessInstanceQuery().processInstanceId(procId).singleResult();\nif (pi != null) { runtimeService.activateProcessInstanceById(procId); }","handlingStrategy":"validation","validationCode":"ProcessInstance pi = runtimeService.createProcessInstanceQuery()\n    .processInstanceId(id).singleResult();\nif (pi == null) { throw new IllegalStateException(\"No running process instance \" + id); }","typeGuard":null,"tryCatchPattern":"try {\n    runtimeService.activateProcessInstanceById(id);\n} catch (ActivitiObjectNotFoundException e) {\n    if (e.getMessage().startsWith(\"Cannot find processInstance for id\")) {\n        logger.warn(\"Instance {} no longer running\", id);\n    } else { throw e; }\n}","preventionTips":["Check ProcessInstanceQuery existence before suspend/activate","Treat instance ids as ephemeral — re-query instead of caching across long jobs","Verify you are connected to the intended database/environment"],"tags":["process-instance","not-found","workflow","activiti"],"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"}