Skip to content

Commit

Permalink
Fix NPE in network validation (#3187)
Browse files Browse the repository at this point in the history
* Fix NPE in network validation
* avoid duplicated code getting current validation level; improve readability

Signed-off-by: Luma <zamarrenolm@aia.es>

Co-authored-by: Olivier Perrin <olivier.perrin@rte-france.com>
(cherry picked from commit 71e153e)
  • Loading branch information
zamarrenolm authored and olperr1 committed Oct 28, 2024
1 parent e755b10 commit 3ad31b0
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1259,15 +1259,13 @@ public ValidationLevel getValidationLevel() {
}

@Override
public Network setMinimumAcceptableValidationLevel(ValidationLevel validationLevel) {
Objects.requireNonNull(validationLevel);
if (this.validationLevel == null) {
this.validationLevel = ValidationUtil.validate(Collections.unmodifiableCollection(index.getAll()), false, false, this.validationLevel, ReportNode.NO_OP);
public Network setMinimumAcceptableValidationLevel(ValidationLevel minLevel) {
Objects.requireNonNull(minLevel);
ValidationLevel currentLevel = getValidationLevel();
if (currentLevel.compareTo(minLevel) < 0) {
throw new ValidationException(this, "Network should be corrected in order to correspond to validation level " + minLevel);
}
if (this.validationLevel.compareTo(validationLevel) < 0) {
throw new ValidationException(this, "Network should be corrected in order to correspond to validation level " + validationLevel);
}
this.minValidationLevel = validationLevel;
this.minValidationLevel = minLevel;
return this;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -687,4 +687,20 @@ public void testPermanentLimitOnUnselectedOperationalLimitsGroup() {
assertTrue(Double.isNaN(currentLimits.getPermanentLimit()));
assertEquals(ValidationLevel.EQUIPMENT, network.getValidationLevel());
}

@Test
void testSetMinimumAcceptableValidationLevelOnInvalidatedNetwork() {
Network network = Network.create("test", "iidm");
network.setMinimumAcceptableValidationLevel(ValidationLevel.EQUIPMENT);
VoltageLevel vl = network.newSubstation().setId("s1").add()
.newVoltageLevel().setId("vl1").setNominalV(100).setTopologyKind(TopologyKind.NODE_BREAKER).add();
Load l1 = vl.newLoad().setId("l1").setNode(0).add();
assertEquals(ValidationLevel.EQUIPMENT, network.getValidationLevel());

l1.setP0(10.0);
l1.setQ0(1.0);

network.setMinimumAcceptableValidationLevel(ValidationLevel.STEADY_STATE_HYPOTHESIS);
assertEquals(ValidationLevel.STEADY_STATE_HYPOTHESIS, network.getValidationLevel());
}
}

0 comments on commit 3ad31b0

Please sign in to comment.