Skip to content

Commit

Permalink
fix(engine): prevent NPE during termination
Browse files Browse the repository at this point in the history
A command could contain multiple terminate instruction that result in the termination of the same element instance. For example, when we have a sub process and a nested element. If both this sub process and the nested element are part of the terminate instructions, the nested element will be terminated twice.

When we receive the command we verify that all instances exist. However, once the first terminate instruction terminates the element, the instance no longer exist for the second terminate instruction. When this occurs we should ignore the terminate instruction.
  • Loading branch information
remcowesterhoud committed Oct 5, 2022
1 parent 5df6a7d commit 43b0a1d
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,12 @@ public void processRecord(
instruction -> {
final var elementInstance =
elementInstanceState.getInstance(instruction.getElementInstanceKey());
if (elementInstance == null) {
// at this point this element instance has already been terminated as a result of
// one of the previous terminate instructions. As a result we no longer need to
// terminate it.
return;
}
final var flowScopeKey = elementInstance.getValue().getFlowScopeKey();

terminateElement(elementInstance, sideEffectQueue);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1004,13 +1004,14 @@ public void shouldTerminateMultiInstanceBodyAndNestedElements() {
.withElementId("A")
.withElementType(BpmnElementType.MULTI_INSTANCE_BODY)
.getFirst();
RecordingExporter.processInstanceRecords(ProcessInstanceIntent.ELEMENT_ACTIVATED)
.withProcessInstanceKey(processInstanceKey)
.withElementId("B")
.withElementType(BpmnElementType.USER_TASK)
.limit(3)
.map(Record::getKey)
.toList();
Assertions.assertThat(
RecordingExporter.processInstanceRecords(ProcessInstanceIntent.ELEMENT_ACTIVATED)
.withProcessInstanceKey(processInstanceKey)
.withElementId("B")
.withElementType(BpmnElementType.USER_TASK)
.limit(3))
.describedAs("Expect that all 3 user tasks are activated")
.hasSize(3);
final var elements =
RecordingExporter.processInstanceRecords(ProcessInstanceIntent.ELEMENT_ACTIVATED)
.withProcessInstanceKey(processInstanceKey)
Expand Down

0 comments on commit 43b0a1d

Please sign in to comment.