2525 * <p>
2626 * In case the filter does not match the current element, the Iterator will
2727 * recursive follow the sequence flow until the next matching element was found.
28+ * If the start element is null the Iterator will become empty.
2829 *
2930 */
3031public class BPMNFlowIterator <T > implements Iterator <BPMNElementNode > {
@@ -41,7 +42,8 @@ public class BPMNFlowIterator<T> implements Iterator<BPMNElementNode> {
4142 /**
4243 * Creates a new BPMNFlowIterator with a given filter criteria.
4344 * The method collects all BPMNElements following the given start element and
44- * matching the given filter
45+ * matching the given filter. If the start element is null the Iterator is
46+ * empty.
4547 *
4648 * @param bpmnElementNode
4749 * @param filter
@@ -52,13 +54,16 @@ public BPMNFlowIterator(BPMNElementNode bpmnElementNode, Predicate<BPMNElementNo
5254 this .targetNodes = new ArrayList <>();
5355 this .index = 0 ;
5456 // find all elements
55- findValidNodes (bpmnElementNode );
57+ if (bpmnElementNode != null ) {
58+ findValidNodes (bpmnElementNode );
59+ }
5660 }
5761
5862 /**
5963 * Creates a new BPMNFlowIterator with a given filter criteria.
6064 * The method collects all BPMNElements following the given start element and
61- * matching the given filter
65+ * matching the given filter. If the start element is null the Iterator is
66+ * empty.
6267 *
6368 * @param bpmnElementNode
6469 * @param filter
@@ -73,7 +78,9 @@ public BPMNFlowIterator(BPMNElementNode bpmnElementNode, Predicate<BPMNElementNo
7378 this .targetNodes = new ArrayList <>();
7479 this .index = 0 ;
7580 // find all elements
76- findValidNodes (bpmnElementNode );
81+ if (bpmnElementNode != null ) {
82+ findValidNodes (bpmnElementNode );
83+ }
7784 }
7885
7986 @ Override
@@ -99,6 +106,9 @@ public BPMNElementNode next() {
99106 * @param currentNode
100107 */
101108 private void findValidNodes (BPMNElementNode currentNode ) {
109+ if (currentNode == null ) {
110+ return ;
111+ }
102112 Set <SequenceFlow > flowSet = currentNode .getOutgoingSequenceFlows ();
103113 // Check if the sequence flow has a condition and evaluate it if a
104114 // conditionEvaluator is defined
@@ -107,12 +117,14 @@ private void findValidNodes(BPMNElementNode currentNode) {
107117 }
108118
109119 for (SequenceFlow flow : flowSet ) {
110- BPMNElementNode node = getTargetNode (flow );// flow.getTargetElement();
111- if (filter .test (node )) {
112- targetNodes .add (node );
113- } else {
114- // if the node does not match the filter go ahead by a recursive call....
115- findValidNodes (node );
120+ BPMNElementNode node = getTargetNode (flow );
121+ if (node != null ) {
122+ if (filter .test (node )) {
123+ targetNodes .add (node );
124+ } else {
125+ // if the node does not match the filter go ahead by a recursive call....
126+ findValidNodes (node );
127+ }
116128 }
117129 }
118130 }
0 commit comments