mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
IDEA-119663 false positive Constant conditions & exceptions: "Argument ... might be null"
This commit is contained in:
+2
-3
@@ -1849,13 +1849,12 @@ public class ControlFlowAnalyzer extends JavaElementVisitor {
|
||||
return null;
|
||||
}
|
||||
|
||||
PsiExpression qualifier = refExpr.getQualifierExpression();
|
||||
if (qualifier == null) {
|
||||
if (DfaValueFactory.isEffectivelyUnqualified(refExpr)) {
|
||||
return myFactory.getVarFactory().createVariableValue(var, refExpr.getType(), false, null);
|
||||
}
|
||||
|
||||
if (!(var instanceof PsiField) || !var.hasModifierProperty(PsiModifier.TRANSIENT) && !var.hasModifierProperty(PsiModifier.VOLATILE)) {
|
||||
DfaVariableValue qualifierValue = createChainedVariableValue(qualifier);
|
||||
DfaVariableValue qualifierValue = createChainedVariableValue(refExpr.getQualifierExpression());
|
||||
if (qualifierValue != null) {
|
||||
return myFactory.getVarFactory().createVariableValue(var, refExpr.getType(), false, qualifierValue);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,46 @@
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
public class TestInspection {
|
||||
|
||||
private static class StringWrapper {
|
||||
private String inner = null;
|
||||
|
||||
@Nullable
|
||||
public String getString() {
|
||||
return inner;
|
||||
}
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private final StringWrapper wrapper;
|
||||
|
||||
@Nullable
|
||||
private String string = null;
|
||||
|
||||
public TestInspection() {
|
||||
wrapper = new StringWrapper();
|
||||
}
|
||||
|
||||
public void doTest() {
|
||||
if (this.wrapper.getString() != null) {
|
||||
doSomething(this.wrapper.getString());
|
||||
}
|
||||
if (this.wrapper.getString() != null) {
|
||||
doSomething(wrapper.getString());
|
||||
}
|
||||
if (wrapper.getString() != null) {
|
||||
doSomething(this.wrapper.getString());
|
||||
}
|
||||
if (wrapper.getString() != null) {
|
||||
doSomething(wrapper.getString());
|
||||
}
|
||||
if (this.string != null) {
|
||||
doSomething(this.string);
|
||||
}
|
||||
}
|
||||
|
||||
private void doSomething(@NotNull String s) {
|
||||
//...
|
||||
}
|
||||
}
|
||||
@@ -104,6 +104,7 @@ public class DataFlowInspectionTest extends LightCodeInsightFixtureTestCase {
|
||||
public void testChainedFinalFieldAccessorsDfa() throws Throwable { doTest(); }
|
||||
public void testAccessorPlusMutator() throws Throwable { doTest(); }
|
||||
public void testClosureVariableField() throws Throwable { doTest(); }
|
||||
public void testOptionalThis() { doTest(); }
|
||||
|
||||
public void testAssigningNullableToNotNull() throws Throwable { doTest(); }
|
||||
public void testAssigningUnknownToNullable() throws Throwable { doTest(); }
|
||||
|
||||
Reference in New Issue
Block a user