[java-dfa] Do not drop NULLABLE when updating dependent variables.

Attempt to fix IDEA-336371 False Negative NPE after instanceof check

GitOrigin-RevId: 1539e33119f58bcd58f20d9015b7c8092d79d02b
This commit is contained in:
Tagir Valeev
2023-10-27 18:20:09 +00:00
committed by intellij-monorepo-bot
parent 264309beb4
commit f2c828e9d8
3 changed files with 23 additions and 1 deletions
@@ -0,0 +1,21 @@
import org.jetbrains.annotations.Contract;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
final class NullFP {
void test(@NotNull Y y) {}
interface X {
@Contract(pure = true)
@Nullable Y getY();
}
interface Y {}
interface Z extends Y {}
void run(@NotNull final X x) {
final Y y = x.getY();
if (y instanceof Z) {}
test(<warning descr="Argument 'x.getY()' might be null">x.getY()</warning>);
}
}
@@ -734,4 +734,5 @@ public class DataFlowInspectionTest extends DataFlowInspectionTestCase {
public void testDuplicatedByPointlessBooleanInspection() { doTest(); }
public void testSystemOutNullSource() { doTest(); }
public void testPrimitiveTypeFieldInWrapper() { doTest(); }
public void testNullWarningAfterInstanceofCheck() { doTest(); }
}
@@ -1276,7 +1276,7 @@ public class DfaMemoryStateImpl implements DfaMemoryState {
type = type.fromRelation(RelationType.EQ);
for (DfaVariableValue value : eqClass.asList()) {
if (value != dfaVar) {
recordVariableType(value, type);
recordVariableType(value, type.meet(value.getInherentType()));
if (!updateQualifierOnEquality(value, value)) return false;
}
}