-
Bug
-
Resolution: Done
-
Major
-
jBPM 3.2.2
-
None
Node, State, and ProcessState don't provide any preliminary check for conditions provided on transitions. No check is performed until the transition is signaled, at which point the process will barf if a condition is present on the default transition, and that condition evaluates to false.
Regardless if a person "should" be using transition conditions in Node or State, the schema allows it, the documentation doesn't forbid it, and the current behavior of a Transition element in the jpdl is inconsistent. The fix to make everything consistent is fairly simple--only org.jbpm.graph.def.Node needs to really be altered (and a one-liner in ProcessState):
In org.jbpm.graph.def.Node, add the following method:
// BRITT--
public Transition calculateLeavingTransition(ExecutionContext executionContext) {
Transition transition = null;
Iterator iter = leavingTransitions.iterator();
while (iter.hasNext()) {
Transition candidate = (Transition) iter.next();
String conditionExpression = candidate.getCondition();
if (conditionExpression != null) {
Object result = JbpmExpressionEvaluator.evaluate(conditionExpression, executionContext);
if (Boolean.TRUE.equals(result))
} else
{ transition = candidate; break; } }
if (transition == null)
return transition;
}
// --BRITT
...and modify "leave(ExecutionContext executionContext)":
// BRITT --replace the following line with the code below
// to check conditions before selecting the transition to take...
//leave(executionContext, getDefaultLeavingTransition()); //original line
leave(executionContext, calculateLeavingTransition(executionContext));
// --BRITT
For consistency, ProcessState should also have one line modified at the very end of it's "leave(ExecutionContext, Transition)" method:
// BRITT-- rather than specify which transition, let the super class decide...
//super.leave(executionContext, getDefaultLeavingTransition());
super.leave(executionContext, calculateLeavingTransition(executionContext));
// --BRITT