mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-01-06 11:50:54 +07:00
data flow inspection: getters without explicit nullable annotation are nullable if their fields are nullable
This commit is contained in:
@@ -110,6 +110,13 @@ public class DfaPsiUtil {
|
||||
return inferParameterNullability((PsiParameter)owner);
|
||||
}
|
||||
|
||||
if (owner instanceof PsiMethod) {
|
||||
PsiField field = PropertyUtil.getFieldOfGetter((PsiMethod)owner);
|
||||
if (field != null && getElementNullability(resultType, field) == Nullness.NULLABLE) {
|
||||
return Nullness.NULLABLE;
|
||||
}
|
||||
}
|
||||
|
||||
return Nullness.UNKNOWN;
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,17 @@
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
class A {
|
||||
@Nullable
|
||||
private final String xxxx = "";
|
||||
|
||||
public String getXxxx() {
|
||||
return xxxx;
|
||||
}
|
||||
}
|
||||
|
||||
class B {
|
||||
|
||||
@NotNull
|
||||
String x = <warning descr="Expression 'new A().getXxxx()' might evaluate to null but is assigned to a variable that is annotated with @NotNull">new A().getXxxx()</warning>;
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
class A {
|
||||
@Nullable
|
||||
private final String xxxx = "";
|
||||
|
||||
@NotNull
|
||||
public String getXxxx() {
|
||||
return xxxx;
|
||||
}
|
||||
}
|
||||
|
||||
class B {
|
||||
|
||||
@NotNull
|
||||
String x = new A().getXxxx();
|
||||
}
|
||||
@@ -542,4 +542,8 @@ public class DataFlowInspectionTest extends DataFlowInspectionTestCase {
|
||||
public void testInnerClass() { doTest(); }
|
||||
public void testCovariantReturn() { doTest(); }
|
||||
public void testArrayInitializerLength() { doTest(); }
|
||||
|
||||
public void testGetterOfNullableFieldIsNotAnnotated() { doTest(); }
|
||||
|
||||
public void testGetterOfNullableFieldIsNotNull() { doTest(); }
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user