Skip to content

Commit f17d60f

Browse files
committed
bugfix: null checks
1 parent f36357f commit f17d60f

1 file changed

Lines changed: 13 additions & 3 deletions

File tree

src/main/java/org/variantsync/vevos/simulation/util/fide/FormulaUtils.java

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,10 @@ public static void flatten(final And and) {
7373
* @return A new formula in which all nodes matching the given predicate are replaced.
7474
*/
7575
public static Node replaceAll(final Node root, final Predicate<Node> who, final Function<Node, Node> replacement) {
76+
if (root == null) {
77+
return null;
78+
}
79+
7680
return replaceAllInplace(root.clone(), who, replacement);
7781
}
7882

@@ -81,14 +85,20 @@ public static Node replaceAll(final Node root, final Predicate<Node> who, final
8185
* This means the given formula (root parameter) will be altered.
8286
*/
8387
public static Node replaceAllInplace(final Node root, final Predicate<Node> who, final Function<Node, Node> replacement) {
88+
if (root == null) {
89+
return null;
90+
}
91+
8492
if (who.test(root)) {
8593
return replacement.apply(root);
8694
} else {
8795
final Node[] children = root.getChildren();
88-
for (int i = 0; i < children.length; ++i) {
89-
children[i] = replaceAllInplace(children[i], who, replacement);
96+
if (children != null) {
97+
for (int i = 0; i < children.length; ++i) {
98+
children[i] = replaceAllInplace(children[i], who, replacement);
99+
}
100+
root.setChildren(children);
90101
}
91-
root.setChildren(children);
92102
return root;
93103
}
94104
}

0 commit comments

Comments
 (0)