diff --git a/network-store-iidm-impl/src/main/java/com/powsybl/network/store/iidm/impl/ConfiguredBusImpl.java b/network-store-iidm-impl/src/main/java/com/powsybl/network/store/iidm/impl/ConfiguredBusImpl.java index 97829d1a0..497b687a8 100644 --- a/network-store-iidm-impl/src/main/java/com/powsybl/network/store/iidm/impl/ConfiguredBusImpl.java +++ b/network-store-iidm-impl/src/main/java/com/powsybl/network/store/iidm/impl/ConfiguredBusImpl.java @@ -14,6 +14,7 @@ import org.apache.commons.collections4.CollectionUtils; import java.util.List; +import java.util.Objects; import java.util.Optional; import java.util.function.*; import java.util.stream.Collectors; @@ -169,7 +170,14 @@ private void updateCalculatedBusAttributesIfNeeded(double newValue, String volta .getCalculatedBusesForBusView(); if (CollectionUtils.isNotEmpty(calculatedBusAttributesList)) { - List calculatedBusesNum = getAllTerminals().stream().map(t -> ((CalculatedBus) t.getBusView().getBus()).getCalculatedBusNum()).distinct().toList(); + List calculatedBusesNum = getAllTerminals().stream().map(t -> { + if (t.getBusView() != null && t.getBusView().getBus() instanceof CalculatedBus) { + CalculatedBus bus = (CalculatedBus) t.getBusView().getBus(); + return bus != null ? bus.getCalculatedBusNum() : null; + } + return null; + }) + .filter(Objects::nonNull).distinct().toList(); List busesToUpdateList = IntStream.range(0, calculatedBusAttributesList.size()) .filter(calculatedBusesNum::contains) .mapToObj(calculatedBusAttributesList::get)