Files
openide/java/java-tests/testData/inspection/dataFlow/fixture/EphemeralInIfChain.java
Tagir Valeev f65c12ccbd [java-dfa] Do not allow null in ephemeral value
GitOrigin-RevId: cca32e434c96998346fc6759f3d699bc6ada799a
2020-10-08 03:09:44 +00:00

51 lines
1.0 KiB
Java

import org.jetbrains.annotations.*;
class Test {
enum MyEnum {A, B, C}
void test(MyEnum x) {
String s = null;
if (x == MyEnum.A) {
s = "A";
}
else if (x == MyEnum.B) {
s = "B";
}
else if (x == MyEnum.C) {
s = "C";
}
System.out.println(s.<warning descr="Method invocation 'trim' may produce 'NullPointerException'">trim</warning>()); // reachable if x is null
}
void test1(@NotNull MyEnum x) {
String s = null;
if (x == MyEnum.A) {
s = "A";
}
else if (x == MyEnum.B) {
s = "B";
}
else if (x == MyEnum.C) {
s = "C";
}
System.out.println(s.trim()); // ephemerably reachable
}
void test2(@NotNull MyEnum x) {
String s = null;
if (x == MyEnum.A) {
s = "A";
}
else if (x == MyEnum.B) {
s = "B";
}
else if (x == MyEnum.C) {
s = "C";
}
if (s == null) {
System.out.println("Incompatible class change!");
return;
}
System.out.println(s.trim());
}
}