Files
openide/java/java-tests/testData/inspection/dataFlow/fixture/EphemeralDefaultCaseVisited.java
T
Tagir Valeevandintellij-monorepo-bot 75d6d70bfe [java-dfa] Introduce ephemeral values (possible only if separate compilation happens)
Now we visit switch default branch, even if it's reachable only on added enum constant
This fixes IDEA-227734 Data flow inspection doesn't report return null inside a switch for @NotNull annotated method
Also if-chains and switch are processed more uniformly: if we replace exhaustive switch statement with the equivalent if, we won't get possible NPE anymore

GitOrigin-RevId: c090b9e76a31a4626b518461b1b4ffce8cd3a7aa
2020-10-06 09:54:49 +00:00

38 lines
871 B
Java

import org.jetbrains.annotations.*;
// IDEA-227734
class Test {
enum MyEnum{ A, B, C }
@NotNull
String doesNotShowWarning(@NotNull MyEnum myEnum){
switch(myEnum){
case A:
case B:
case C:
return "YES";
default: return <warning descr="'null' is returned by the method declared as @NotNull">null</warning>;
}
}
@NotNull
String doesNotShowWarning2(@NotNull final MyEnum myEnum){
switch(myEnum){
case A:
case B:
case C:
return "YES";
}
return <warning descr="'null' is returned by the method declared as @NotNull">null</warning>;
}
@NotNull
String showsWarning(@NotNull MyEnum myEnum){
switch(myEnum){
case A:
case B:
return "YES";
default: return <warning descr="'null' is returned by the method declared as @NotNull">null</warning>;
}
}
}