Better fix for IDEA-184723 Data flow algorithm complexity

"x==null" & "x!=null" facts are merged into "x is NULLABLE"
This commit is contained in:
Tagir Valeev
2018-01-10 17:19:02 +07:00
parent 4fd3db662e
commit 6d52b5462e
4 changed files with 36 additions and 7 deletions
@@ -0,0 +1,31 @@
import org.jetbrains.annotations.*;
class NullabilityBasics {
void test2() {
String x = getNullable();
if (x == null) {
System.out.println("x is null!");
}
if (isEmpty(x) && Math.random() > 0.5) {
return;
}
System.out.println(x.<warning descr="Method invocation 'trim' may produce 'java.lang.NullPointerException'">trim</warning>());
}
@Nullable String getNullable() {
return Math.random() > 0.5 ? null : "";
}
@Contract(value = "null -> true",pure = true)
static boolean isEmpty(@Nullable String s) {
return s == null || s.isEmpty();
}
void test(String x) {
if (x == null) {
System.out.println("x is null!");
}
System.out.println(x.<warning descr="Method invocation 'trim' may produce 'java.lang.NullPointerException'">trim</warning>());
}
}