{"record":{"id":"7cc8e8715b5fdb07","repo":"flowable/flowable-engine","slug":"cannot-set-suspension-state-for-execution-execu","errorCode":null,"errorMessage":"Cannot set suspension state for execution '${executionId}': not a process instance.","messagePattern":"Cannot set suspension state for execution '(.+?)': not a process instance\\.","errorType":"exception","errorClass":"ActivitiException","httpStatus":null,"severity":"error","filePath":"modules/flowable5-engine/src/main/java/org/activiti/engine/impl/cmd/AbstractSetProcessInstanceStateCmd.java","lineNumber":57,"sourceCode":"\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\n            SuspensionStateUtil.setSuspensionState(taskEntity, getNewState());\r\n        }\r\n\r","sourceCodeStart":39,"sourceCodeEnd":75,"githubUrl":"https://github.com/flowable/flowable-engine/blob/d6d39ce1c69ff244f2d9dc6af756a9b95e865586/modules/flowable5-engine/src/main/java/org/activiti/engine/impl/cmd/AbstractSetProcessInstanceStateCmd.java#L39-L75","documentation":"AbstractSetProcessInstanceStateCmd.execute requires the found execution to actually be a process instance (root execution). If the id resolves to a child/concurrent execution, changing the process instance suspension state on it is rejected with an ActivitiException.","triggerScenarios":"Calling suspendProcessInstanceById/activateProcessInstanceById with the id of a child execution or concurrent execution (ExecutionEntity from an execution query / execution listener context) rather than the process instance id.","commonSituations":"Storing Execution.getId() from an intermediate activity instead of the process instance id; iterating executions from createExecutionQuery() and passing every id to the process-instance-level API.","solutions":["Use the processInstanceId: for any execution, executionEntity.getProcessInstanceId() gives the root id to pass to this API.","If you have an Execution object, pass execution.getProcessInstanceId() instead of execution.getId().","Verify with runtimeService.createProcessInstanceQuery().processInstanceId(id).singleResult() that the id denotes a process instance."],"exampleFix":"// before\nruntimeService.suspendProcessInstanceById(execution.getId());\n// after\nruntimeService.suspendProcessInstanceById(execution.getProcessInstanceId());","handlingStrategy":"type-guard","validationCode":"ExecutionEntity e = (ExecutionEntity) runtimeService.createExecutionQuery().executionId(id).singleResult();\nif (e == null || !e.isProcessInstanceType()) { throw new IllegalStateException(\"id is not a process instance\"); }","typeGuard":"boolean isProcessInstance(Execution execution) {\n    return execution instanceof ProcessInstance;\n}","tryCatchPattern":"try {\n    runtimeService.suspendProcessInstanceById(id);\n} catch (ActivitiException e) {\n    if (e.getMessage() != null && e.getMessage().contains(\"not a process instance\")) {\n        String rootId = runtimeService.createExecutionQuery().executionId(id).singleResult().getProcessInstanceId();\n        runtimeService.suspendProcessInstanceById(rootId);\n    } else { throw e; }\n}","preventionTips":["Use execution.getProcessInstanceId() for instance-level APIs","Narrow execution query results with .processInstanceId filter","Cast-check with instanceof ProcessInstance before instance-level calls"],"tags":["process-instance","invalid-state-transition","workflow","activiti"],"backgroundTag":"invalid-state-transition","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"}