Skip to content

Commit 77a7bc4

Browse files
authored
Fix NPE in proof tree when using global filters (#3755)
2 parents 25c50a7 + a12644c commit 77a7bc4

File tree

2 files changed

+22
-14
lines changed

2 files changed

+22
-14
lines changed

key.ui/src/main/java/de/uka/ilkd/key/gui/prooftree/GUIBranchNode.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,11 +47,11 @@ public TreeNode getChildAt(int childIndex) {
4747
* @return number of children
4848
*/
4949
private int fillChildrenCache(boolean dryRun) {
50-
if (childrenCache == null) {
50+
if (childrenCache == null && !dryRun) {
5151
createChildrenCache();
5252
}
5353

54-
if (!childrenCache.isEmpty()) {
54+
if (childrenCache != null && !childrenCache.isEmpty()) {
5555
return childrenCache.size();
5656
}
5757

key.ui/src/main/java/de/uka/ilkd/key/gui/prooftree/GUIProofTreeModel.java

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ public void automaticStateChanged(Goal source, boolean oldAutomatic,
8080
boolean newAutomatic) {
8181
if (!batchGoalStateChange
8282
&& ProofTreeViewFilter.HIDE_INTERACTIVE_GOALS.isActive()) {
83-
updateTree((TreeNode) null);
83+
updateTree((GUIAbstractTreeNode) null);
8484
}
8585
}
8686
};
@@ -135,7 +135,7 @@ public void proofGoalRemoved(ProofTreeEvent e) {
135135
return;
136136
}
137137
if (globalFilterActive()) {
138-
updateTree((TreeNode) null);
138+
updateTree((GUIAbstractTreeNode) null);
139139
} else {
140140
proofStructureChanged(e);
141141
}
@@ -151,7 +151,7 @@ public synchronized void setBatchGoalStateChange(boolean value,
151151
Collection<Node> nodesToUpdate) {
152152
if (!value && batchGoalStateChange) {
153153
if (nodesToUpdate == null || nodesToUpdate.isEmpty()) {
154-
updateTree((TreeNode) null);
154+
updateTree((GUIAbstractTreeNode) null);
155155
} else {
156156
for (Node n : nodesToUpdate) {
157157
updateTree(n);
@@ -190,7 +190,7 @@ public synchronized void setAttentive(boolean b) {
190190
proof.addProofTreeListener(proofTreeListener);
191191
// updateTree(null);
192192
if (globalFilterActive()) {
193-
updateTree((TreeNode) null);
193+
updateTree((GUIAbstractTreeNode) null);
194194
}
195195
} else {
196196
proof.removeProofTreeListener(proofTreeListener);
@@ -276,7 +276,7 @@ public synchronized void setFilter(ProofTreeViewFilter filter, boolean active) {
276276
activeNodeFilter.setActive(false);
277277
activeNodeFilter = null;
278278
}
279-
updateTree((TreeNode) null);
279+
updateTree((GUIAbstractTreeNode) null);
280280
return;
281281
}
282282
if (!filter.global()) {
@@ -286,7 +286,7 @@ public synchronized void setFilter(ProofTreeViewFilter filter, boolean active) {
286286
activeNodeFilter = active ? (NodeFilter) filter : null;
287287
}
288288
filter.setActive(active);
289-
updateTree((TreeNode) null);
289+
updateTree((GUIAbstractTreeNode) null);
290290
}
291291

292292
/**
@@ -398,25 +398,33 @@ public synchronized void valueForPathChanged(TreePath path, Object newValue) {
398398
*
399399
* @param trn tree node to update.
400400
*/
401-
private synchronized void updateTree(TreeNode trn) {
402-
if (trn == null || trn == getRoot()) { // bigger change, redraw whole tree
401+
private synchronized void updateTree(GUIAbstractTreeNode trn) {
402+
403+
// If possible, redraw only a certain subtree
404+
// starting from the lowermost parent of trn that is not hidden
405+
while (trn != null && trn != getRoot()
406+
&& ProofTreeViewFilter.hiddenByGlobalFilters(trn.getNode())) {
407+
trn = (GUIAbstractTreeNode) trn.getParent();
408+
}
409+
410+
// bigger change, redraw whole tree
411+
if (trn == null || trn == getRoot()) {
403412
proofTreeNodes.clear();
404413
branchNodes.clear();
405414
fireTreeStructureChanged(new Object[] { getRoot() });
406415
return;
407416
}
408-
// otherwise redraw only a certain subtree
409-
// starting from the parent of trn
417+
410418
flushCaches(trn);
411419
// also flush the current node, it might be an OSS conceiving children in this step
412-
((GUIAbstractTreeNode) trn).flushCache();
420+
trn.flushCache();
413421
TreeNode[] path = ((GUIAbstractTreeNode) trn.getParent()).getPath();
414422
fireTreeStructureChanged(path);
415423
}
416424

417425
public synchronized void updateTree(Node p_node) {
418426
if (p_node == null) {
419-
updateTree((TreeNode) null);
427+
updateTree((GUIAbstractTreeNode) null);
420428
} else {
421429
updateTree(getProofTreeNode(p_node));
422430
}

0 commit comments

Comments
 (0)