mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-22 11:29:28 +07:00
31 lines
807 B
Java
31 lines
807 B
Java
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 '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 'NullPointerException'">trim</warning>());
|
|
}
|
|
} |