mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-01-06 03:21:12 +07:00
[java-dfa] Avoid flushing constants before closures
LiveVariableAnalyzer should know that the constant is used in closure. Otherwise, it may flush it. Fixes IDEA-262325 Nullability issue when constant checked outside of lambda is used inside GitOrigin-RevId: 660beecec912efbaceec77e71bfcfbca43fd97ad
This commit is contained in:
committed by
intellij-monorepo-bot
parent
1b615aa69c
commit
1c366664e9
@@ -776,10 +776,13 @@ public class ControlFlowAnalyzer extends JavaElementVisitor {
|
||||
if (PsiUtil.isJvmLocalVariable(target)) {
|
||||
variables.add((PsiVariable)target);
|
||||
}
|
||||
if (target instanceof PsiMember && !((PsiMember)target).hasModifierProperty(PsiModifier.STATIC)) {
|
||||
DfaValue qualifier = getFactory().getExpressionFactory().getQualifierOrThisValue(expression);
|
||||
if (qualifier instanceof DfaVariableValue) {
|
||||
escapedVars.add((DfaVariableValue)qualifier);
|
||||
if (target instanceof PsiMember) {
|
||||
DfaValue escapedVar = getFactory().getExpressionFactory().getQualifierOrThisValue(expression);
|
||||
if (escapedVar == null) {
|
||||
escapedVar = getFactory().createValue(expression);
|
||||
}
|
||||
if (escapedVar instanceof DfaVariableValue) {
|
||||
escapedVars.add((DfaVariableValue)escapedVar);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,22 @@
|
||||
import org.jetbrains.annotations.*;
|
||||
|
||||
public class ConstantInClosure {
|
||||
static final Object CONST = init();
|
||||
|
||||
private void test() {
|
||||
Obj obj = new Obj();
|
||||
if (CONST != null) {
|
||||
privateMethod();
|
||||
Runnable runnable = () -> consume(CONST);
|
||||
}
|
||||
}
|
||||
|
||||
private void privateMethod() { }
|
||||
|
||||
native void consume(@NotNull Object obj);
|
||||
|
||||
@Nullable
|
||||
static native Object init();
|
||||
|
||||
private static class Obj { }
|
||||
}
|
||||
@@ -329,4 +329,5 @@ public class DataFlowInspection8Test extends DataFlowInspectionTestCase {
|
||||
public void testModifyListInLambda() {
|
||||
doTest();
|
||||
}
|
||||
public void testConstantInClosure() { doTest(); }
|
||||
}
|
||||
Reference in New Issue
Block a user