Skip to content

Commit

Permalink
Replace AssertionError by IllegalStateException. (#2465)
Browse files Browse the repository at this point in the history
Signed-off-by: Coline PILOQUET <coline.piloquet@rte-france.com>
  • Loading branch information
colinepiloquet authored Mar 8, 2023
1 parent a5249aa commit ffeeb1b
Show file tree
Hide file tree
Showing 171 changed files with 357 additions and 329 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ public Object visitLoadingRank(LoadingRankNode node, Void arg) {
List<String> sortedBranchIds = sortBranches(branchIds);
int i = sortedBranchIds.indexOf(branchIdToRank);
if (i == -1) {
throw new AssertionError();
throw new IllegalStateException();
}
return sortedBranchIds.size() - i; // just a convention
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ public Void visitNetworkComponent(NetworkComponentNode node, Void arg) {
out.write("switch_");
break;
default:
throw new AssertionError();
throw new IllegalStateException();
}
out.write("('");
out.write(node.getComponentId());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ private Map<String, Boolean> getActions() {

private RuleContext evaluateRule(Rule rule, RunningContext context) {
if (rule.getCondition().getType() != ConditionType.EXPRESSION) {
throw new AssertionError("TODO");
throw new IllegalStateException("TODO");
}
ExpressionNode conditionExpr = ((ExpressionCondition) rule.getCondition()).getNode();
EvaluationContext evalContext = new EvaluationContext() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,9 @@ void test() throws IOException {

LoadFlowActionSimulatorConfig config = LoadFlowActionSimulatorConfig.load(platformConfig);

assertEquals("LoadFlowMock", config.getLoadFlowName().orElseThrow(AssertionError::new));
assertEquals("LoadFlowMock", config.getLoadFlowName().orElseThrow(IllegalStateException::new));
config.setLoadFlowName("AnotherLoadFlowMock");
assertEquals("AnotherLoadFlowMock", config.getLoadFlowName().orElseThrow(AssertionError::new));
assertEquals("AnotherLoadFlowMock", config.getLoadFlowName().orElseThrow(IllegalStateException::new));

assertEquals(15, config.getMaxIterations());
config.setMaxIterations(10);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -330,7 +330,7 @@ private boolean isOnlyMainCc() {
return false;

default:
throw new AssertionError();
throw new IllegalStateException();
}
}

Expand Down Expand Up @@ -1198,7 +1198,7 @@ private boolean exportLoad(AmplExportContext context, String busId) {
case ONLY_MAIN_CC_AND_CONNECTABLE_GENERATORS_AND_SHUNTS:
return isBusExported(context, busId);
default:
throw new AssertionError();
throw new IllegalStateException();
}
}

Expand Down Expand Up @@ -1293,7 +1293,7 @@ private boolean exportGeneratorOrShunt(AmplExportContext context, String busId,
case ONLY_MAIN_CC_AND_CONNECTABLE_GENERATORS_AND_SHUNTS_AND_ALL_LOADS:
return isBusExported(context, conBusId);
default:
throw new AssertionError();
throw new IllegalStateException();
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,7 @@ private static String representativeVoltageLevelId(Collection<String> voltageLev
return voltageLevelIds.stream()
.sorted()
.findFirst()
.orElseThrow(() -> new AssertionError("Unexpected: voltageLevelIds list is empty"));
.orElseThrow(() -> new IllegalStateException("Unexpected: voltageLevelIds list is empty"));
}

private String representativeSubstationId(Collection<String> substationIds) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,9 @@ protected AbstractConductingEquipmentConversion(
// It is assumed the property bags are already sorted
this.numTerminals = ps.size();
terminals = new TerminalData[] {null, null, null};
assert numTerminals <= 3;
if (numTerminals > 3) {
throw new IllegalStateException("numTerminals should be less or equal to 3 but is " + numTerminals);
}
for (int k = 1; k <= numTerminals; k++) {
int k0 = k - 1;
terminals[k0] = new TerminalData(CgmesNames.TERMINAL, ps.get(k0), context);
Expand Down Expand Up @@ -464,7 +466,9 @@ PowerFlow powerFlowSV(int n) {
// Terminals

protected void convertedTerminals(Terminal... ts) {
assert ts.length == numTerminals;
if (ts.length != numTerminals) {
throw new IllegalStateException();
}
for (int k = 0; k < ts.length; k++) {
int n = k + 1;
Terminal t = ts[k];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ public OperationalLimitConversion(PropertyBag l, Context context) {
case CURRENT_LIMIT:
return holder::newCurrentLimits;
default:
throw new AssertionError();
throw new IllegalStateException();
}
}

Expand All @@ -97,7 +97,7 @@ public OperationalLimitConversion(PropertyBag l, Context context) {
case CURRENT_LIMIT:
return b::newCurrentLimits1;
default:
throw new AssertionError();
throw new IllegalStateException();
}
}

Expand All @@ -113,7 +113,7 @@ public OperationalLimitConversion(PropertyBag l, Context context) {
case CURRENT_LIMIT:
return b::newCurrentLimits2;
default:
throw new AssertionError();
throw new IllegalStateException();
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ public void convert() {
});
modelAdder.add();
} else {
throw new AssertionError("Unexpected shunt type: " + shuntType);
throw new IllegalStateException("Unexpected shunt type: " + shuntType);
}
identify(adder);
connect(adder);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,9 @@ public void convert() {

String iidmSubstationId = context.substationIdMapping().substationIidm(id);
Substation substation = context.network().getSubstation(iidmSubstationId);
assert substation == null;
if (substation != null) {
throw new IllegalStateException("Substation should be null");
}
SubstationAdder adder = context.network().newSubstation()
.setId(iidmSubstationId)
.setName(iidmName())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ public static int getTerminalSequenceNumber(Terminal t) {
case TWO:
return 2;
default:
throw new AssertionError("Incorrect branch side " + ((Branch<?>) c).getSide(t));
throw new IllegalStateException("Incorrect branch side " + ((Branch<?>) c).getSide(t));
}
} else if (c instanceof ThreeWindingsTransformer) {
switch (((ThreeWindingsTransformer) c).getSide(t)) {
Expand All @@ -230,7 +230,7 @@ public static int getTerminalSequenceNumber(Terminal t) {
case THREE:
return 3;
default:
throw new AssertionError("Incorrect three-windings transformer side " + ((ThreeWindingsTransformer) c).getSide(t));
throw new IllegalStateException("Incorrect three-windings transformer side " + ((ThreeWindingsTransformer) c).getSide(t));
}
} else {
throw new PowsyblException("Unexpected Connectable instance: " + c.getClass());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ private static void writeShuntCompensators(Network network, String cimNamespace,
shuntType = "Nonlinear";
break;
default:
throw new AssertionError("Unexpected shunt model type: " + s.getModelType());
throw new IllegalStateException("Unexpected shunt model type: " + s.getModelType());
}
boolean controlEnabled = s.isVoltageRegulatorOn();

Expand Down Expand Up @@ -453,7 +453,7 @@ private static String switchClassname(SwitchKind kind) {
case LOAD_BREAK_SWITCH:
return "LoadBreakSwitch";
default:
throw new AssertionError("Unexpected switch king " + kind);
throw new IllegalStateException("Unexpected switch king " + kind);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,12 +74,12 @@ void microGridOperationalLimits() throws IOException {
assertEquals(1312.0, ln.getCurrentLimits2().map(LoadingLimits::getPermanentLimit).orElse(0.0), 0.0);

assertEquals(1, (int) ln.getCurrentLimits1().map(lim -> lim.getTemporaryLimits().size()).orElse(-1));
TemporaryLimit lntl1 = ln.getCurrentLimits1().flatMap(lim -> lim.getTemporaryLimits().stream().findFirst()).orElseThrow(AssertionError::new);
TemporaryLimit lntl1 = ln.getCurrentLimits1().flatMap(lim -> lim.getTemporaryLimits().stream().findFirst()).orElseThrow(IllegalStateException::new);
assertEquals(500.0, lntl1.getValue(), 0.0);
assertEquals(10, lntl1.getAcceptableDuration());

assertEquals(1, (int) ln.getCurrentLimits2().map(lim -> lim.getTemporaryLimits().size()).orElse(-1));
TemporaryLimit lntl2 = ln.getCurrentLimits2().flatMap(lim -> lim.getTemporaryLimits().stream().findFirst()).orElseThrow(AssertionError::new);
TemporaryLimit lntl2 = ln.getCurrentLimits2().flatMap(lim -> lim.getTemporaryLimits().stream().findFirst()).orElseThrow(IllegalStateException::new);
assertEquals(500.0, lntl2.getValue(), 0.0);
assertEquals(10, lntl2.getAcceptableDuration());

Expand All @@ -88,12 +88,12 @@ void microGridOperationalLimits() throws IOException {
assertEquals(1226.0, tln.getCurrentLimits2().map(LoadingLimits::getPermanentLimit).orElse(0.0), 0.0);

assertEquals(1, (int) tln.getCurrentLimits1().map(lim -> lim.getTemporaryLimits().size()).orElse(-1));
TemporaryLimit tlntl1 = tln.getCurrentLimits1().flatMap(lim -> lim.getTemporaryLimits().stream().findFirst()).orElseThrow(AssertionError::new);
TemporaryLimit tlntl1 = tln.getCurrentLimits1().flatMap(lim -> lim.getTemporaryLimits().stream().findFirst()).orElseThrow(IllegalStateException::new);
assertEquals(500.0, tlntl1.getValue(), 0.0);
assertEquals(10, tlntl1.getAcceptableDuration());

assertEquals(1, (int) tln.getCurrentLimits2().map(lim -> lim.getTemporaryLimits().size()).orElse(-1));
TemporaryLimit tlntl2 = ln.getCurrentLimits2().flatMap(lim -> lim.getTemporaryLimits().stream().findFirst()).orElseThrow(AssertionError::new);
TemporaryLimit tlntl2 = ln.getCurrentLimits2().flatMap(lim -> lim.getTemporaryLimits().stream().findFirst()).orElseThrow(IllegalStateException::new);
assertEquals(500.0, tlntl2.getValue(), 0.0);
assertEquals(10, tlntl2.getAcceptableDuration());
}
Expand Down Expand Up @@ -206,12 +206,12 @@ void smallGridOperationalLimits() throws IOException {
assertEquals(1000.0, ln.getCurrentLimits2().map(LoadingLimits::getPermanentLimit).orElse(0.0), 0.0);

assertEquals(1, (int) ln.getCurrentLimits1().map(l -> l.getTemporaryLimits().size()).orElse(-1));
TemporaryLimit lntl1 = ln.getCurrentLimits1().flatMap(l -> l.getTemporaryLimits().stream().findFirst()).orElseThrow(AssertionError::new);
TemporaryLimit lntl1 = ln.getCurrentLimits1().flatMap(l -> l.getTemporaryLimits().stream().findFirst()).orElseThrow(IllegalStateException::new);
assertEquals(500.0, lntl1.getValue(), 0.0);
assertEquals(900, lntl1.getAcceptableDuration());

assertEquals(1, (int) ln.getCurrentLimits2().map(l -> l.getTemporaryLimits().size()).orElse(-1));
TemporaryLimit lntl2 = ln.getCurrentLimits2().flatMap(l -> l.getTemporaryLimits().stream().findFirst()).orElseThrow(AssertionError::new);
TemporaryLimit lntl2 = ln.getCurrentLimits2().flatMap(l -> l.getTemporaryLimits().stream().findFirst()).orElseThrow(IllegalStateException::new);
assertEquals(500.0, lntl2.getValue(), 0.0);
assertEquals(900, lntl2.getAcceptableDuration());
}
Expand Down Expand Up @@ -264,12 +264,12 @@ void svedalaOperationalLimits() throws IOException {
assertEquals(2970.0, ln.getCurrentLimits2().map(LoadingLimits::getPermanentLimit).orElse(0.0), 0.0);

assertEquals(1, (int) ln.getCurrentLimits1().map(l -> l.getTemporaryLimits().size()).orElse(-1));
TemporaryLimit lntl1 = ln.getCurrentLimits1().flatMap(l -> l.getTemporaryLimits().stream().findFirst()).orElseThrow(AssertionError::new);
TemporaryLimit lntl1 = ln.getCurrentLimits1().flatMap(l -> l.getTemporaryLimits().stream().findFirst()).orElseThrow(IllegalStateException::new);
assertEquals(500.0, lntl1.getValue(), 0.0);
assertEquals(600, lntl1.getAcceptableDuration());

assertEquals(1, (int) ln.getCurrentLimits2().map(l -> l.getTemporaryLimits().size()).orElse(-1));
TemporaryLimit lntl2 = ln.getCurrentLimits2().flatMap(l -> l.getTemporaryLimits().stream().findFirst()).orElseThrow(AssertionError::new);
TemporaryLimit lntl2 = ln.getCurrentLimits2().flatMap(l -> l.getTemporaryLimits().stream().findFirst()).orElseThrow(IllegalStateException::new);
assertEquals(500.0, lntl2.getValue(), 0.0);
assertEquals(600, lntl2.getAcceptableDuration());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -381,7 +381,7 @@ private void compareShuntModels(ShuntCompensator expected, ShuntCompensator actu
}
break;
default:
throw new AssertionError("Unexpected shunt model type: " + expected.getModelType());
throw new IllegalStateException("Unexpected shunt model type: " + expected.getModelType());
}
}

Expand Down Expand Up @@ -490,7 +490,7 @@ private void compareGeneratorReactiveLimits(ReactiveLimits expected, ReactiveLim
break;

default:
throw new AssertionError("Unexpected ReactiveLimitsKing value: " + expected.getKind());
throw new IllegalStateException("Unexpected ReactiveLimitsKing value: " + expected.getKind());
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -135,12 +135,12 @@ public boolean hasProfileUri(String profileUri) {

@Override
public String getProfileUri(String profile) {
throw new AssertionError("Unsupported CIM version 14");
throw new IllegalStateException("Unsupported CIM version 14");
}

@Override
public String getProfile(String profileUri) {
throw new AssertionError("Unsupported CIM version 14");
throw new IllegalStateException("Unsupported CIM version 14");
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ private Attribute anonymizeAttribute(Attribute attribute) {
return null;
}
} else {
throw new AssertionError("Unknown attribute " + attribute.getName());
throw new IllegalStateException("Unknown attribute " + attribute.getName());
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,9 +89,9 @@ public String getUsageFooter() {
@Override
public void run(CommandLine line, ToolRunningContext context) throws Exception {
ToolOptions options = new ToolOptions(line, context.getFileSystem());
Path cimZipPath = options.getPath("cim-path").orElseThrow(AssertionError::new);
Path outputDir = options.getPath("output-dir").orElseThrow(AssertionError::new);
Path mappingFile = options.getPath("mapping-file").orElseThrow(AssertionError::new);
Path cimZipPath = options.getPath("cim-path").orElseThrow(IllegalStateException::new);
Path outputDir = options.getPath("output-dir").orElseThrow(IllegalStateException::new);
Path mappingFile = options.getPath("mapping-file").orElseThrow(IllegalStateException::new);
boolean skipExternalRef = options.hasOption("skip-external-refs");

CimAnonymizer anomymizer = new CimAnonymizer();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ static DataSource createDataSource(Path directory, String basename, CompressionF
case ZSTD:
return new ZstdFileDataSource(directory, basename, observer);
default:
throw new AssertionError("Unexpected CompressionFormat value: " + compressionExtension);
throw new IllegalStateException("Unexpected CompressionFormat value: " + compressionExtension);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ public TypedValue deserialize(JsonParser p, DeserializationContext deserializati
break;

default:
throw new AssertionError("Unexpected field: " + p.getCurrentName());
throw new IllegalStateException("Unexpected field: " + p.getCurrentName());
}
}

Expand Down
2 changes: 1 addition & 1 deletion commons/src/main/java/com/powsybl/commons/util/Colors.java
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ private static long[] hsvToRgb(double h, double s, double v) {
b = q;
break;
default:
throw new AssertionError();
throw new IllegalStateException();
}
return new long[] {Math.round(r * 256), Math.round(g * 256), Math.round(b * 256)};
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,11 +54,11 @@ void test() {
assertEquals(Collections.singletonList("Default"), config.getProfiles());

assertFalse(config.getBaseVoltageName(500, "Default").isPresent());
assertEquals("vl300to500", config.getBaseVoltageName(450, "Default").orElseThrow(AssertionError::new));
assertEquals("vl300to500", config.getBaseVoltageName(400, "Default").orElseThrow(AssertionError::new));
assertEquals("vl300to500", config.getBaseVoltageName(300, "Default").orElseThrow(AssertionError::new));
assertEquals("vl180to300", config.getBaseVoltageName(250, "Default").orElseThrow(AssertionError::new));
assertEquals("vl180to300", config.getBaseVoltageName(180, "Default").orElseThrow(AssertionError::new));
assertEquals("vl300to500", config.getBaseVoltageName(450, "Default").orElseThrow(IllegalStateException::new));
assertEquals("vl300to500", config.getBaseVoltageName(400, "Default").orElseThrow(IllegalStateException::new));
assertEquals("vl300to500", config.getBaseVoltageName(300, "Default").orElseThrow(IllegalStateException::new));
assertEquals("vl180to300", config.getBaseVoltageName(250, "Default").orElseThrow(IllegalStateException::new));
assertEquals("vl180to300", config.getBaseVoltageName(180, "Default").orElseThrow(IllegalStateException::new));
assertFalse(config.getBaseVoltageName(700, "Default").isPresent());
assertFalse(config.getBaseVoltageName(400, "unknownProfile").isPresent());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ private void preProcess(Path workingDir, Command command, int executionIndex) th
break;

default:
throw new AssertionError("Unexpected FilePreProcessor value: " + file.getPreProcessor());
throw new IllegalStateException("Unexpected FilePreProcessor value: " + file.getPreProcessor());
}
}
}
Expand Down Expand Up @@ -258,7 +258,7 @@ private int process(Path workingDir, CommandExecution commandExecution, int exec
}
break;
default:
throw new AssertionError("Unexpected CommandType value: " + command.getType());
throw new IllegalStateException("Unexpected CommandType value: " + command.getType());
}
return exitValue;
}
Expand All @@ -280,7 +280,7 @@ private void postProcess(Path workingDir, CommandExecution commandExecution, int
}

} else {
throw new AssertionError("Unexpected FilePostProcessor value: " + file.getPostProcessor());
throw new IllegalStateException("Unexpected FilePostProcessor value: " + file.getPostProcessor());
}
}
}
Expand Down
Loading

0 comments on commit ffeeb1b

Please sign in to comment.