EndEventParseHandler not setting correct error code for ErrorEndEventActivityBehavior
Describe the bug
Error end events use the errorRef attribute as the error code, but they should be using the error code of the error pointed by the ref. What happens in the EndEventParserHandler.executeParse method class at (snip):
ErrorEventDefinition errorDefinition = (ErrorEventDefinition) eventDefinition;
if (bpmnParse.getBpmnModel().containsErrorRef(errorDefinition.getErrorCode())) {
String errorCode = bpmnParse.getBpmnModel().getErrors().get(errorDefinition.getErrorCode());
if (StringUtils.isEmpty(errorCode)) {
LOGGER.warn("errorCode is required for an error event {}", endEvent.getId());
}
}
endEvent.setBehavior(bpmnParse.getActivityBehaviorFactory().createErrorEndEventActivityBehavior(endEvent, errorDefinition));
Is that the errorCode from the model's error map is not given to the assigned errorDefinition activity. So, String errorCode does contain the right error code, but it's not set to the ErrorEndEventActivity.
The behaviour seems to be a regression in Flowable 6. If we look at the code from flowable5:
org.flowable.bpmn.model.ErrorEventDefinition errorDefinition = (org.flowable.bpmn.model.ErrorEventDefinition) eventDefinition;
if (bpmnParse.getBpmnModel().containsErrorRef(errorDefinition.getErrorCode())) {
String errorCode = bpmnParse.getBpmnModel().getErrors().get(errorDefinition.getErrorCode());
if (StringUtils.isEmpty(errorCode)) {
LOGGER.warn("errorCode is required for an error event {}", endEvent.getId());
}
endEventActivity.setProperty("type", "errorEndEvent");
errorDefinition.setErrorCode(errorCode);
}
endEventActivity.setActivityBehavior(bpmnParse.getActivityBehaviorFactory().createErrorEndEventActivityBehavior(endEvent, errorDefinition));
On line 58 we see the errorCode being set to the errorDefinition. If we compare the code between escalation and error events, the behaviour in both was to assign the correct code to the created ActivityBehavior class.
Expected behavior
The error code of the created ErrorEndEvent should be the error code of the error pointed by the error definition referenced by the errorRef attribute, not the value of the errorRef itself.
Additional context flowable-engine 6.6.0
I also want to point out the documentation mentions that if there is no <error> referenced by the errorRef, then the errorRef SHOULD itself be used as the error code. I understand OP is referring to when the <error> does exist, but keep that in mind when fixing OPs issue! Thank you!
"If an errorRef is provided, but no error is defined in the BPMN 2.0 file, then the errorRef is used as errorCode (similar for with error end events)." - Source
I also want to point out the documentation mentions that if there is no
referenced by the errorRef, then the errorRef SHOULD itself be used as the error code. I understand OP is referring to when the does exist, but keep that in mind when fixing OPs issue! Thank you!
I think this logic is actually handled in the code. Specifically, this branch:
if (bpmnParse.getBpmnModel().containsErrorRef(errorDefinition.getErrorCode())) {
So if the error referenced by the errorRef is there, that is used to set the error code. That bit seems to be missing, compare it with the code for EscalationEndEventDefinition:
} else if (eventDefinition instanceof EscalationEventDefinition) {
EscalationEventDefinition escalationDefinition = (EscalationEventDefinition) eventDefinition;
Escalation escalation = null;
if (bpmnParse.getBpmnModel().containsEscalationRef(escalationDefinition.getEscalationCode())) {
escalation = bpmnParse.getBpmnModel().getEscalation(escalationDefinition.getEscalationCode());
String escalationCode = escalation.getEscalationCode();
if (StringUtils.isEmpty(escalationCode)) {
LOGGER.warn("escalationCode is required for an escalation event {}", endEvent.getId());
}
}
endEvent.setBehavior(bpmnParse.getActivityBehaviorFactory().createEscalationEndEventActivityBehavior(endEvent, escalationDefinition, escalation));
}