From 5e6501934cc478ddaacca57a8d9b5503584c46d2 Mon Sep 17 00:00:00 2001 From: Flowable Contributor Date: Fri, 27 Nov 2026 15:03:52 +0800 Subject: [PATCH] Fix potential NullPointerException in AbstractDynamicStateManager (#4067) When moveActivityIdToSubProcessInstanceActivityId is called to move an active execution into a call activity subprocess instance, a NullPointerException can occur in AbstractDynamicStateManager.createEmbeddedSubProcessAndExecutions. This change adds null safety checks in four locations: - When the resolved sub process is null, a descriptive FlowableException is thrown indicating the sub process could not be resolved. - When subProcess.getInitialFlowElement returns null, a descriptive FlowableException is thrown indicating a missing start event. - When newChildExecutions is empty after creating child executions, a descriptive FlowableException is thrown. - When the default continue parent execution is null, a descriptive FlowableException is thrown instead of an NPE later in the call chain. --- .../dynamic/AbstractDynamicStateManager.java | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/modules/flowable-engine/src/main/java/org/flowable/engine/impl/dynamic/AbstractDynamicStateManager.java b/modules/flowable-engine/src/main/java/org/flowable/engine/impl/dynamic/AbstractDynamicStateManager.java index 9c6b73241c1..3e67765bfd0 100644 --- a/modules/flowable-engine/src/main/java/org/flowable/engine/impl/dynamic/AbstractDynamicStateManager.java +++ b/modules/flowable-engine/src/main/java/org/flowable/engine/impl/dynamic/AbstractDynamicStateManager.java @@ -574,7 +574,20 @@ protected void doMoveExecutionState(ProcessInstanceChangeState processInstanceCh if (moveExecutionContainer.isMoveToSubProcessInstance()) { CallActivity callActivity = moveExecutionContainer.getCallActivity(); Process subProcess = moveExecutionContainer.getSubProcessModel().getProcessById(moveExecutionContainer.getSubProcessDefKey()); - ExecutionEntity callActivityInstanceExecution = createCallActivityInstance(callActivity, moveExecutionContainer.getSubProcessDefinition(), newChildExecutions.get(0), subProcess.getInitialFlowElement().getId(), commandContext); + if (subProcess == null) { + throw new FlowableException("Could not find sub process with key '" + moveExecutionContainer.getSubProcessDefKey() + + "' in the sub process model. Call activity '" + callActivity.getId() + "' references a sub process that could not be resolved."); + } + FlowElement initialFlowElement = subProcess.getInitialFlowElement(); + if (initialFlowElement == null) { + throw new FlowableException("No initial flow element found in sub process '" + subProcess.getId() + + "'. The sub process definition may be missing a start event."); + } + if (newChildExecutions.isEmpty()) { + throw new FlowableException("No child executions were created for the sub process instance move to call activity '" + + callActivity.getId() + "'."); + } + ExecutionEntity callActivityInstanceExecution = createCallActivityInstance(callActivity, moveExecutionContainer.getSubProcessDefinition(), newChildExecutions.get(0), initialFlowElement.getId(), commandContext); List moveExecutions = moveExecutionContainer.getExecutions(); MoveExecutionEntityContainer subProcessMoveExecutionEntityContainer = new MoveExecutionEntityContainer(moveExecutions, @@ -849,6 +862,10 @@ protected List createEmbeddedSubProcessAndExecutions(Collection // The default parent execution is retrieved from the match with the first source execution ExecutionEntity defaultContinueParentExecution = moveExecutionEntityContainer.getContinueParentExecution(movingExecutions.get(0).getId()); + if (defaultContinueParentExecution == null) { + throw new FlowableException("No continue parent execution found for execution '" + movingExecutions.get(0).getId() + + "'. This may indicate that the parent execution could not be resolved during the state change."); + } Set movingExecutionIds = movingExecutions.stream().map(ExecutionEntity::getId).collect(Collectors.toSet()); // Build the subProcess hierarchy