mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-01-05 01:50:56 +07:00
[java-dfa] Test for IDEA-357456
GitOrigin-RevId: b7b97300c5a4512009b006cdfafeba56bcfe4c69
This commit is contained in:
committed by
intellij-monorepo-bot
parent
49f0880f57
commit
84ce93ddc5
@@ -0,0 +1,29 @@
|
||||
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");
|
||||
};
|
||||
}
|
||||
|
||||
}
|
||||
@@ -133,4 +133,6 @@ public class DataFlowInspection21Test extends DataFlowInspectionTestCase {
|
||||
public void testArrayAddedIntoCollection() { doTest(); }
|
||||
|
||||
public void testInstanceOfPatternAffectNullity() { doTest(); }
|
||||
|
||||
public void testNullabilityInEnumSwitch() { doTest(); }
|
||||
}
|
||||
Reference in New Issue
Block a user