mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
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:
@@ -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>());
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user