mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-21 20:54:49 +07:00
GitOrigin-RevId: b7b97300c5a4512009b006cdfafeba56bcfe4c69
29 lines
816 B
Java
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");
|
|
};
|
|
}
|
|
|
|
} |