Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prevent NPE when terminating call activity #10996

Merged
merged 1 commit into from
Nov 22, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -572,7 +572,9 @@ private void terminateElement(
} else if (elementType == BpmnElementType.CALL_ACTIVITY) {
final var calledActivityElementInstance =
elementInstanceState.getInstance(elementInstance.getCalledChildInstanceKey());
terminateElement(calledActivityElementInstance, sideEffects);
if (calledActivityElementInstance != null && calledActivityElementInstance.canTerminate()) {
terminateElement(calledActivityElementInstance, sideEffects);
}
}

stateWriter.appendFollowUpEvent(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import io.camunda.zeebe.model.bpmn.builder.SubProcessBuilder;
import io.camunda.zeebe.protocol.record.Record;
import io.camunda.zeebe.protocol.record.RecordType;
import io.camunda.zeebe.protocol.record.intent.IncidentIntent;
import io.camunda.zeebe.protocol.record.intent.JobIntent;
import io.camunda.zeebe.protocol.record.intent.ProcessInstanceIntent;
import io.camunda.zeebe.protocol.record.intent.ProcessInstanceModificationIntent;
Expand Down Expand Up @@ -850,6 +851,54 @@ public void shouldActivateParallelGateway() {
.hasSize(4);
}

@Test
public void verifyCallActivityWithIncidentInOutputMappingCanBeTerminated() {
final var child = Bpmn.createExecutableProcess("child").startEvent().endEvent().done();
final var parent =
Bpmn.createExecutableProcess(PROCESS_ID)
.startEvent()
.callActivity("callActivity", c -> c.zeebeProcessId("child"))
.zeebeOutputExpression("x", "y")
.manualTask("task")
.endEvent()
.done();

ENGINE.deployment().withXmlResource(child).withXmlResource(parent).deploy();

final var processInstanceKey = ENGINE.processInstance().ofBpmnProcessId(PROCESS_ID).create();

final var callActivityElement =
RecordingExporter.processInstanceRecords(ProcessInstanceIntent.ELEMENT_ACTIVATED)
.withProcessInstanceKey(processInstanceKey)
.withElementId("callActivity")
.withElementType(BpmnElementType.CALL_ACTIVITY)
.getFirst();

Assertions.assertThat(
RecordingExporter.incidentRecords(IncidentIntent.CREATED)
.withProcessInstanceKey(processInstanceKey)
.getFirst())
.extracting(r -> r.getValue().getElementId())
.isEqualTo("callActivity");

ENGINE
.processInstance()
.withInstanceKey(processInstanceKey)
.modification()
.activateElement("task")
.terminateElement(callActivityElement.getKey())
.modify();

verifyThatRootElementIsActivated(processInstanceKey, "task", BpmnElementType.MANUAL_TASK);
verifyThatProcessInstanceIsCompleted(processInstanceKey);
remcowesterhoud marked this conversation as resolved.
Show resolved Hide resolved
Assertions.assertThat(
RecordingExporter.processInstanceRecords(ProcessInstanceIntent.ELEMENT_TERMINATED)
.withProcessInstanceKey(processInstanceKey)
.withElementId(callActivityElement.getValue().getElementId())
.exists())
.isTrue();
}

private static void verifyThatRootElementIsActivated(
final long processInstanceKey, final String elementId, final BpmnElementType elementType) {
verifyThatElementIsActivated(processInstanceKey, elementId, elementType, processInstanceKey);
Expand Down