diff --git a/action/action-util/src/main/java/com/powsybl/action/util/ProportionalScalable.java b/action/action-util/src/main/java/com/powsybl/action/util/ProportionalScalable.java index eb0f63a8462..93d4f334373 100644 --- a/action/action-util/src/main/java/com/powsybl/action/util/ProportionalScalable.java +++ b/action/action-util/src/main/java/com/powsybl/action/util/ProportionalScalable.java @@ -90,6 +90,12 @@ private static void checkPercentages(List percentages, List sca if (scalables.size() != percentages.size()) { throw new IllegalArgumentException("percentage and scalable list must have the same size"); } + if (scalables.isEmpty()) { + return; + } + if (percentages.stream().anyMatch(p -> Float.isNaN(p))) { + throw new IllegalArgumentException("There is at least one undefined percentage"); + } double sum = percentages.stream().mapToDouble(Double::valueOf).sum(); if (Math.abs(100 - sum) > EPSILON) { throw new IllegalArgumentException(String.format("Sum of percentages must be equals to 100 (%.2f)", sum)); diff --git a/action/action-util/src/test/java/com/powsybl/action/util/ScalableTest.java b/action/action-util/src/test/java/com/powsybl/action/util/ScalableTest.java index 6649252d69e..db3fc4e9a46 100644 --- a/action/action-util/src/test/java/com/powsybl/action/util/ScalableTest.java +++ b/action/action-util/src/test/java/com/powsybl/action/util/ScalableTest.java @@ -83,7 +83,6 @@ public void testInitialValue() { assertEquals(0., Scalable.proportional(Arrays.asList(70.f, 30.f), Arrays.asList(g1, l1)).initialValue(network), 1e-3); testInvalidProportionalScalable(Collections.singletonList(100.0f), Collections.emptyList()); - testInvalidProportionalScalable(Collections.emptyList(), Collections.emptyList()); testInvalidProportionalScalable(Arrays.asList(70.f, 20.f), Arrays.asList(g1, l1)); }