IDEA-209947 Explain possible NPE

GitOrigin-RevId: dab1e1bfa33e2cdc0f1ab833f943bd24d171b882
This commit is contained in:
Tagir Valeev
2019-04-29 11:04:15 +03:00
committed by intellij-monorepo-bot
parent c098599bd5
commit a175181df4
7 changed files with 121 additions and 16 deletions
@@ -1,6 +1,6 @@
/*
Value is always false (null == s)
Parameter 's' is annotated as 'non-null' (@NotNull String s)
Parameter 's' is annotated as 'non-null' (@NotNull)
*/
import org.jetbrains.annotations.NotNull;
@@ -0,0 +1,16 @@
/*
May be null (s)
's' was assigned (loadString())
Method 'loadString' is annotated as 'nullable' (@Nullable)
*/
import org.jetbrains.annotations.Nullable;
class Test {
void test() {
String s = loadString();
System.out.println(<selection>s</selection>.trim());
}
native @Nullable String loadString();
}
@@ -0,0 +1,14 @@
/*
May be null (s)
An execution might exist where:
's' is known to be 'null' from line #9 (s == null)
*/
class Test {
void test(String s) {
if (s == null) {
System.out.println(s);
}
System.out.println(<selection>s</selection>.trim());
}
}
@@ -0,0 +1,17 @@
/*
May be null (foo)
'foo' was assigned (getFoo())
Method 'getFoo' is annotated as 'nullable' (@Nullable)
*/
import org.jetbrains.annotations.Nullable;
class Test {
void test(Object x) {
String foo = (String)getFoo();
System.out.println(<selection>foo</selection>.trim());
}
@Nullable native Object getFoo();
}