Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix NPE in network validation #3187

Merged
merged 3 commits into from
Oct 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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());
}
}