mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
IDEA-137195 Not annotated constant fields should be treated as Nullable or NotNull when static code analysis is able to prove Nullable/NotNull
This commit is contained in:
+79
@@ -0,0 +1,79 @@
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
class Super {
|
||||
public Super() {
|
||||
this(2);
|
||||
}
|
||||
|
||||
public Super(int a) {
|
||||
staticMethod();
|
||||
}
|
||||
|
||||
static void staticMethod() {}
|
||||
|
||||
}
|
||||
|
||||
class Test {
|
||||
@Nullable
|
||||
private static Object getNull() {
|
||||
return null;
|
||||
}
|
||||
|
||||
private static final Object CONST = getNull();
|
||||
|
||||
public static void test() {
|
||||
System.out.println(<warning descr="Method invocation 'CONST.toString()' may produce 'java.lang.NullPointerException'">CONST.toString()</warning>);
|
||||
}
|
||||
}
|
||||
|
||||
class Test2 extends Super {
|
||||
@NotNull
|
||||
private static Object getNotNull() {
|
||||
return new Object();
|
||||
}
|
||||
|
||||
private static final Object CONST = getNotNull();
|
||||
|
||||
public static void test() {
|
||||
System.out.println(CONST.toString());
|
||||
}
|
||||
}
|
||||
|
||||
class Test3 {
|
||||
|
||||
private static final Object CONST = "";
|
||||
|
||||
public static void test() {
|
||||
System.out.println(CONST.toString());
|
||||
}
|
||||
}
|
||||
|
||||
class Test4 {
|
||||
|
||||
public enum Day {
|
||||
SUNDAY, MONDAY, TUESDAY, WEDNESDAY,
|
||||
THURSDAY, FRIDAY, SATURDAY
|
||||
}
|
||||
|
||||
private static final Day CONST = Day.FRIDAY;
|
||||
|
||||
public static void test() {
|
||||
System.out.println(CONST.toString());
|
||||
}
|
||||
}
|
||||
|
||||
class Test5 {
|
||||
private final String something = new String("something");
|
||||
private final String somethingElse = "somethingElse";
|
||||
|
||||
public Integer someLength() {
|
||||
//May produce nullpointer warning
|
||||
return something.length();
|
||||
}
|
||||
|
||||
public Integer someElseLength() {
|
||||
//No warning
|
||||
return somethingElse.length();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user