GP-4530 - Graphing - Fixed NPE when using dummy source nodes

This commit is contained in:
dragonmacher 2024-04-16 18:56:08 -04:00
parent 190f1eaa1e
commit 075c8110f3
2 changed files with 27 additions and 2 deletions

View file

@ -232,7 +232,7 @@ public class ChkDominanceAlgorithm<V, E extends GEdge<V>> extends AbstractDomina
}
V dominator = getImmediateDominator(v);
if (!Objects.equals(dominator, v)) {
if (dominator != null && !Objects.equals(dominator, v)) {
dg.addEdge(new DefaultGEdge<>(dominator, v));
}
}

View file

@ -320,6 +320,31 @@ public class GraphAlgorithmsTest extends AbstractGraphAlgorithmsTest {
}
@SuppressWarnings("unchecked")
@Test
public void testDominance_GetDominatorGraph_WithDummySource() throws CancelledException {
TestV v1 = vertex(1);
TestV v2 = vertex(2);
TestV v3 = vertex(3);
TestV v4 = vertex(4);
//
// 3 sources; 1 sink
//
// This will trigger the algorithm to use a unifying dummy node for the source. This used
// to lead to a NullPointerException when trying to process the dummy as a dominator.
//
edge(v2, v1);
edge(v3, v1);
edge(v4, v1);
GDirectedGraph<TestV, GEdge<TestV>> dg =
GraphAlgorithms.findDominanceTree(g, TaskMonitor.DUMMY);
assertContainsEdgesExactly(dg);
}
@Test
public void testDominance_GetDominators_Complicated() throws CancelledException {
@ -1924,7 +1949,7 @@ public class GraphAlgorithmsTest extends AbstractGraphAlgorithmsTest {
assertThat(entries.size(), is(3));
assertThat(entries, hasItems(v1, v4));
assertThat(entries, hasItem(isOneOf(v5, v6, v7)));
assertThat(entries, hasItem(is(oneOf(v5, v6, v7))));
}