Skip to content

Commit

Permalink
'#39 Implement code to avoid NPE
Browse files Browse the repository at this point in the history
  • Loading branch information
patrickdalla committed Jul 1, 2024
1 parent 98c7e50 commit 0adcf3a
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,11 @@ public void setRootName(String rootName) {
}

public boolean hasFilter(IFilter iFilter) {
return filtersToNodeMap.get(iFilter).size() > 0;
Set<DecisionNode> nodes = filtersToNodeMap.get(iFilter);
if (nodes != null) {
return filtersToNodeMap.get(iFilter).size() > 0;
}
return false;
}

public HashMap<IFilter, Set<DecisionNode>> getFiltersToNodeMap() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@ public void remove(DecisionNode value) {
Set<DecisionNode> nodes = model.getFiltersToNodeMap().get(filterNode.getFilter());
if (nodes != null) {
nodes.remove(filterNode);
if (nodes.size() == 0) {
model.getFiltersToNodeMap().remove(filterNode.getFilter());
}
}
}
children.remove(value);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package iped.app.ui.filterdecisiontree;

import java.util.Set;

import iped.app.ui.CombinedFilterTreeModel;
import iped.viewers.api.IFilter;

Expand All @@ -25,7 +27,10 @@ public DecisionNode clone() {
FilterNode clone = new FilterNode(filter, model);
clone.parent = this.parent;
clone.inverted = this.inverted;
model.getFiltersToNodeMap().get(filter).add(this);
Set<DecisionNode> nodes = model.getFiltersToNodeMap().get(filter);
if (nodes != null) {
nodes.add(this);
}
return clone;
}

Expand Down

0 comments on commit 0adcf3a

Please sign in to comment.