{"record":{"id":"d44a48b3fc6ad808","repo":"flowable/flowable-engine","slug":"the-new-process-definition-key-key-does-no","errorCode":null,"errorMessage":"The new process definition (key = '<key>') does not contain the current activity (id = '<activityId>') of the process instance (id = '<processInstanceId>').","messagePattern":"The new process definition \\(key = '<key>'\\) does not contain the current activity \\(id = '<activityId>'\\) of the process instance \\(id = '<processInstanceId>'\\)\\.","errorType":"exception","errorClass":"ActivitiException","httpStatus":null,"severity":"error","filePath":"modules/flowable5-engine/src/main/java/org/activiti/engine/impl/cmd/SetProcessDefinitionVersionCmd.java","lineNumber":122,"sourceCode":"        validateAndSwitchVersionOfExecution(commandContext, processInstance, newProcessDefinition);\n\n        // switch the historic process instance to the new process definition version\n        commandContext.getHistoryManager().recordProcessDefinitionChange(processInstanceId, newProcessDefinition.getId());\n\n        // switch all sub-executions of the process instance to the new process definition version\n        List<ExecutionEntity> childExecutions = executionManager\n                .findChildExecutionsByProcessInstanceId(processInstanceId);\n        for (ExecutionEntity executionEntity : childExecutions) {\n            validateAndSwitchVersionOfExecution(commandContext, executionEntity, newProcessDefinition);\n        }\n\n        return null;\n    }\n\n    protected void validateAndSwitchVersionOfExecution(CommandContext commandContext, ExecutionEntity execution, ProcessDefinitionEntity newProcessDefinition) {\n        // check that the new process definition version contains the current activity\n        if (execution.getActivity() != null && !newProcessDefinition.contains(execution.getActivity())) {\n            throw new ActivitiException(\n                    \"The new process definition \" +\n                            \"(key = '\" + newProcessDefinition.getKey() + \"') \" +\n                            \"does not contain the current activity \" +\n                            \"(id = '\" + execution.getActivity().getId() + \"') \" +\n                            \"of the process instance \" +\n                            \"(id = '\" + processInstanceId + \"').\");\n        }\n\n        // switch the process instance to the new process definition version\n        execution.setProcessDefinition(newProcessDefinition);\n\n        // and change possible existing tasks (as the process definition id is stored there too)\n        List<TaskEntity> tasks = commandContext.getTaskEntityManager().findTasksByExecutionId(execution.getId());\n        for (TaskEntity taskEntity : tasks) {\n            taskEntity.setProcessDefinitionId(newProcessDefinition.getId());\n            commandContext.getHistoryManager().recordTaskProcessDefinitionChange(taskEntity.getId(), newProcessDefinition.getId());\n        }\n    }","sourceCodeStart":104,"sourceCodeEnd":140,"githubUrl":"https://github.com/flowable/flowable-engine/blob/d6d39ce1c69ff244f2d9dc6af756a9b95e865586/modules/flowable5-engine/src/main/java/org/activiti/engine/impl/cmd/SetProcessDefinitionVersionCmd.java#L104-L140","documentation":"validateAndSwitchVersionOfExecution verifies that every activity the execution is currently sitting in exists in the new process definition version (ProcessDefinitionEntity.contains). If the new version removed or renamed that activity, migrating would leave the instance pointing at a nonexistent flow element, so ActivitiException is thrown.","triggerScenarios":"runtimeService.setProcessDefinitionVersion(pid, v) where version v of the same key was deployed after deleting/renaming a BPMN activity (userTask/serviceTask id) that the instance is currently waiting in.","commonSituations":"Redeploying a changed BPMN model that removed a user task while instances were still waiting on it; renaming element ids across versions; migrating an instance stuck mid-branch of a deleted subprocess.","solutions":["Keep removed activities as deprecated pass-through elements (or keep their ids stable) in the new BPMN version before migrating.","Deploy a compatibility version of the diagram that still contains the missing activity id, migrate, then move the flow manually (changeActivityState / moveExecutionActivityIdTo on newer engines).","Pick a target version that still contains the activity: inspect DeploymentManager/BpmnModel for the version before calling the command."],"exampleFix":"// before\n// new version 3 of order.bpmn removed <userTask id=\"manualReview\">\nruntimeService.setProcessDefinitionVersion(pid, 3);\n// after\n// keep the element in version 3: <userTask id=\"manualReview\" .../> (optionally behind a skip condition)\nruntimeService.setProcessDefinitionVersion(pid, 3);","handlingStrategy":"validation","validationCode":"// verify the activity exists in the target version before migrating\nProcessDefinition pd = repositoryService.createProcessDefinitionQuery()\n    .processDefinitionKey(key).processDefinitionVersion(version).singleResult();\nBpmnModel model = repositoryService.getBpmnModel(pd.getId());\nboolean contains = model.getFlowElement(currentActivityId) != null\n    || model.getMainProcess().getFlowElement(currentActivityId) != null;","typeGuard":null,"tryCatchPattern":"try {\n    runtimeService.setProcessDefinitionVersion(pid, version);\n} catch (org.activiti.engine.ActivitiException e) {\n    if (e.getMessage() != null && e.getMessage().contains(\"does not contain the current activity\")) {\n        // fall back to a compatible version or adjust the model\n    }\n}","preventionTips":["Keep activity ids stable across BPMN versions","Never remove activities from a definition while instances wait on them","Diff successive BPMN versions before deploying breaking changes"],"tags":["java","flowable","process-migration","bpmn-model"],"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-18T11:17:12.947Z"}