{"record":{"id":"1caa6854a3eda382","repo":"flowable/flowable-engine","slug":"the-new-process-definition-key-newprocessdef","errorCode":null,"errorMessage":"The new process definition (key = '${newProcessDefinition.getKey()}') does not contain the current activity (id = '${execution.getActivityId()}') of the process instance (id = '${processInstanceId}').","messagePattern":"The new process definition \\(key = '(.+?)'\\) does not contain the current activity \\(id = '(.+?)'\\) of the process instance \\(id = '(.+?)'\\)\\.","errorType":"exception","errorClass":"FlowableException","httpStatus":null,"severity":"error","filePath":"modules/flowable-engine/src/main/java/org/flowable/engine/impl/cmd/SetProcessDefinitionVersionCmd.java","lineNumber":120,"sourceCode":"        validateAndSwitchVersionOfExecution(commandContext, processInstance, newProcessDefinition);\n\n        // switch the historic process instance to the new process definition version\n        CommandContextUtil.getHistoryManager(commandContext).recordProcessDefinitionChange(processInstanceId, newProcessDefinition.getId());\n\n        // switch all sub-executions of the process instance to the new process definition version\n        Collection<ExecutionEntity> childExecutions = executionManager.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, ProcessDefinition newProcessDefinition) {\n        // check that the new process definition version contains the current activity\n        org.flowable.bpmn.model.Process process = ProcessDefinitionUtil.getProcess(newProcessDefinition.getId());\n        if (execution.getActivityId() != null && process.getFlowElement(execution.getActivityId(), true) == null) {\n            throw new FlowableException(\"The new process definition \" + \"(key = '\" + newProcessDefinition.getKey() + \"') \" + \"does not contain the current activity \" + \"(id = '\"\n                    + execution.getActivityId() + \"') \" + \"of the process instance \" + \"(id = '\" + processInstanceId + \"').\");\n        }\n\n        // switch the process instance to the new process definition version\n        execution.setProcessDefinitionId(newProcessDefinition.getId());\n        execution.setProcessDefinitionName(newProcessDefinition.getName());\n        execution.setProcessDefinitionKey(newProcessDefinition.getKey());\n\n        // and change possible existing tasks (as the process definition id is stored there too)\n        ProcessEngineConfigurationImpl processEngineConfiguration = CommandContextUtil.getProcessEngineConfiguration(commandContext);\n        List<TaskEntity> tasks = processEngineConfiguration.getTaskServiceConfiguration().getTaskService().findTasksByExecutionId(execution.getId());\n        Clock clock = processEngineConfiguration.getClock();\n        for (TaskEntity taskEntity : tasks) {\n            taskEntity.setProcessDefinitionId(newProcessDefinition.getId());\n            processEngineConfiguration.getActivityInstanceEntityManager().recordTaskInfoChange(taskEntity, clock.getCurrentTime());\n        }\n    }\n","sourceCodeStart":102,"sourceCodeEnd":138,"githubUrl":"https://github.com/flowable/flowable-engine/blob/d6d39ce1c69ff244f2d9dc6af756a9b95e865586/modules/flowable-engine/src/main/java/org/flowable/engine/impl/cmd/SetProcessDefinitionVersionCmd.java#L102-L138","documentation":"Before switching versions, the command checks that the new process definition version contains the activity the execution is currently sitting on. If the activity id does not resolve in the new BPMN model (including subprocess scopes), it throws FlowableException, because the execution could not continue after the switch.","triggerScenarios":"Migrating a running instance whose current activity was added/renamed/removed in the new definition version, so process.getFlowElement(activityId, true) returns null.","commonSituations":"Redeploying a refactored BPMN where activity ids changed; instances parked at a boundary/subprocess activity deleted in the newer version; uncontrolled model drift between versions.","solutions":["Keep activity ids stable across definition versions when redeploying","Move the instance off the missing activity (complete/signal it) before migrating, or migrate when it sits at a stable wait state present in both versions","Add the missing activity (with the same id) to the new definition version and redeploy","Use a migration tool (Flowable migration/ProcessInstanceMigration) that maps activity ids explicitly"],"exampleFix":"// before\n// new version renamed userTask id 'review' to 'managerReview' then migrated\nnew SetProcessDefinitionVersionCmd(piId, 5);\n// after\norg.flowable.bpmn.model.Process p = ProcessDefinitionUtil.getProcess(newDefId);\nif (p.getFlowElement(currentActivityId, true) != null) {\n    new SetProcessDefinitionVersionCmd(piId, 5);\n}","handlingStrategy":"try-catch","validationCode":"org.flowable.bpmn.model.Process p = ProcessDefinitionUtil.getProcess(newDef.getId());\nboolean compatible = execution.getActivityId() == null || p.getFlowElement(execution.getActivityId(), true) != null;","typeGuard":null,"tryCatchPattern":"try { cmd.execute(ctx); } catch (FlowableException e) { if (e.getMessage().contains(\"does not contain the current activity\")) { /* defer migration or remap activity */ } }","preventionTips":["Keep activity ids stable across versions","Migrate only at wait states present in both versions","Review BPMN diffs between versions before redeploying","Use Flowable's process instance migration API with explicit activity mappings"],"tags":["bpmn","migration","process-definition"],"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"}