From c434837714f19bd3baa0a3d99f31c35586d37f8a Mon Sep 17 00:00:00 2001 From: Mathieu BAGUE Date: Tue, 25 Jun 2019 09:25:18 +0200 Subject: [PATCH] Fix traverser in CalculatedBusImpl to handle properly internal connections (#838) (#841) Signed-off-by: Mathieu BAGUE --- .../iidm/network/impl/CalculatedBusImpl.java | 2 +- .../impl/EmptyCalculatedBusBugTest.java | 24 +++++++++++++++++++ 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/iidm/iidm-impl/src/main/java/com/powsybl/iidm/network/impl/CalculatedBusImpl.java b/iidm/iidm-impl/src/main/java/com/powsybl/iidm/network/impl/CalculatedBusImpl.java index c282eb3e3ab..ddb5df9231b 100644 --- a/iidm/iidm-impl/src/main/java/com/powsybl/iidm/network/impl/CalculatedBusImpl.java +++ b/iidm/iidm-impl/src/main/java/com/powsybl/iidm/network/impl/CalculatedBusImpl.java @@ -52,7 +52,7 @@ private static NodeTerminal findTerminal(NodeBreakerVoltageLevel voltageLevel, T // Traverse the graph until a valid NodeTerminal is found VoltageLevel.NodeBreakerView.Traverser traverser = (node1, sw, node2) -> { - if (sw.isOpen()) { + if (sw != null && sw.isOpen()) { return false; } terminal[0] = (NodeTerminal) voltageLevel.getNodeBreakerView().getTerminal(node2); diff --git a/iidm/iidm-impl/src/test/java/com/powsybl/iidm/network/impl/EmptyCalculatedBusBugTest.java b/iidm/iidm-impl/src/test/java/com/powsybl/iidm/network/impl/EmptyCalculatedBusBugTest.java index d44975d15bd..b8ca43497c2 100644 --- a/iidm/iidm-impl/src/test/java/com/powsybl/iidm/network/impl/EmptyCalculatedBusBugTest.java +++ b/iidm/iidm-impl/src/test/java/com/powsybl/iidm/network/impl/EmptyCalculatedBusBugTest.java @@ -10,6 +10,7 @@ import org.junit.Test; import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; /** * ArrayIndexOutOfBoundsException fix test @@ -48,4 +49,27 @@ public void test() { network = createNetwork(true); assertEquals(2, network.getVoltageLevel("VL").getBusBreakerView().getBusStream().count()); } + + @Test + public void testNullPointer() { + Network network = createNetwork(true); + + VoltageLevel vl = network.getVoltageLevel("VL"); + vl.getNodeBreakerView() + .setNodeCount(3) + .newInternalConnection() + .setId("IC") + .setNode1(1) + .setNode2(2) + .add(); + + Load l1 = vl.newLoad() + .setId("L1") + .setNode(0) + .setP0(100.0) + .setQ0(50.0) + .add(); + + assertNotNull(l1.getTerminal().getBusBreakerView().getBus()); + } }