Files
openide/java/java-tests/testData/inspection/dataFlow/fixture/NullabilityInEnumSwitch.java
T
Tagir Valeevandintellij-monorepo-bot 84ce93ddc5 [java-dfa] Test for IDEA-357456
GitOrigin-RevId: b7b97300c5a4512009b006cdfafeba56bcfe4c69
2024-09-02 21:01:25 +00:00

29 lines
816 B
Java

import org.jetbrains.annotations.Nullable;
// IDEA-357456
public class NullabilityInEnumSwitch {
enum Option {
A(false),
B(true),
C(true);
private final boolean needsValue;
Option(boolean needsValue) {
this.needsValue = needsValue;
}
}
static boolean test(@Nullable String value, Option option) {
if (option.needsValue && value == null) throw new IllegalArgumentException();
return switch (option) {
case A -> true;
// Too hard to analyze: we should go back into needsValue initializer
case B -> value.<warning descr="Method invocation 'isEmpty' may produce 'NullPointerException'">isEmpty</warning>();
case C -> value.<warning descr="Method invocation 'startsWith' may produce 'NullPointerException'">startsWith</warning>("a");
};
}
}