mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
Enum.valueOf and annotations methods are not-null (IDEA-151305, IDEA-151174)
This commit is contained in:
@@ -70,9 +70,18 @@ public class DfaPsiUtil {
|
||||
return Nullness.UNKNOWN;
|
||||
}
|
||||
|
||||
if (owner instanceof PsiEnumConstant) {
|
||||
if (owner instanceof PsiEnumConstant || PsiUtil.isAnnotationMethod(owner)) {
|
||||
return Nullness.NOT_NULL;
|
||||
}
|
||||
if (owner instanceof PsiMethod) {
|
||||
PsiMethod method = (PsiMethod)owner;
|
||||
if ("valueOf".equals(method.getName()) && method.hasModifierProperty(PsiModifier.STATIC)) {
|
||||
PsiClass containingClass = method.getContainingClass();
|
||||
if (containingClass != null && containingClass.isEnum()) {
|
||||
return Nullness.NOT_NULL;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (resultType != null) {
|
||||
NullableNotNullManager nnn = NullableNotNullManager.getInstance(owner.getProject());
|
||||
|
||||
@@ -0,0 +1,11 @@
|
||||
class Test {
|
||||
@interface FooBar {
|
||||
String x();
|
||||
}
|
||||
|
||||
static void baz(FooBar annotation) {
|
||||
if (<warning descr="Condition 'annotation.x() == null' is always 'false'">annotation.x() == null</warning>) {
|
||||
System.out.println("null");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -12,6 +12,10 @@ class FooWithComments {
|
||||
}
|
||||
}
|
||||
|
||||
boolean checkValueOf(String name) {
|
||||
return <warning descr="Condition 'AnEnum.valueOf(name) != null' is always 'true'">AnEnum.valueOf(name) != null</warning>;
|
||||
}
|
||||
|
||||
private native void anotherMethod(String name);
|
||||
|
||||
@Nullable
|
||||
|
||||
@@ -91,6 +91,8 @@ public class DataFlowInspectionTest extends DataFlowInspectionTestCase {
|
||||
public void testGreaterIsNotEquals() throws Throwable { doTest(); }
|
||||
public void testNotGreaterIsNotEquals() throws Throwable { doTest(); }
|
||||
|
||||
public void testAnnotationMethodNotNull() { doTest(); }
|
||||
|
||||
public void testChainedFinalFieldsDfa() throws Throwable { doTest(); }
|
||||
public void testFinalFieldsDifferentInstances() throws Throwable { doTest(); }
|
||||
public void testThisFieldGetters() throws Throwable { doTest(); }
|
||||
|
||||
Reference in New Issue
Block a user