[java-dfa] IDEA-354336 Java DFA fails to report nullable var passed to notnull arg after instanceof

GitOrigin-RevId: 2fada677a054fbd049e12e9b585a5f08711a5b26
This commit is contained in:
Tagir Valeev
2024-06-21 13:49:37 +00:00
committed by intellij-monorepo-bot
parent c05ea7c662
commit 3b45af56a7
3 changed files with 25 additions and 1 deletions
@@ -0,0 +1,22 @@
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
class Main {
Record foo() {
PsiFile file = fooBar();
if (file instanceof PsiCompiledFile compiledFile) {
return new Record(compiledFile);
}
return new Record(<warning descr="Argument 'file' might be null">file</warning>);
}
@Nullable
private PsiFile fooBar() {
return null;
}
interface PsiFile {}
interface PsiCompiledFile extends PsiFile {}
private record Record(@NotNull PsiFile file) {}
}
@@ -130,4 +130,6 @@ public class DataFlowInspection21Test extends DataFlowInspectionTestCase {
public void testArrayElementWrappedInPureMethod() { doTest(); }
public void testArrayAddedIntoCollection() { doTest(); }
public void testInstanceOfPatternAffectNullity() { doTest(); }
}
@@ -1290,7 +1290,7 @@ public class DfaMemoryStateImpl implements DfaMemoryState {
type = type.fromRelation(RelationType.EQ);
for (DfaVariableValue value : eqClass.asList()) {
if (value != dfaVar) {
recordVariableType(value, type.meet(value.getInherentType()));
recordVariableType(value, type.meet(getDfType(value)));
if (!updateQualifierOnEquality(value, value)) return false;
}
}