mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-01-07 22:09:38 +07:00
[java-dfa] Return source value from assignment when target is not a variable
Fixes IDEA-346500 Assignment of non-null value to volatile field might be null GitOrigin-RevId: 1105f7ed467e038df48922b036895faae40cc304
This commit is contained in:
committed by
intellij-monorepo-bot
parent
3c5f1db918
commit
388ce94e56
@@ -93,16 +93,14 @@ public class AssignInstruction extends ExpressionPushingInstruction {
|
||||
dfaSource = dfaSource.getFactory().fromDfType(refType.dropLocality());
|
||||
}
|
||||
}
|
||||
if (!(psi instanceof PsiField field) || !field.hasModifierProperty(PsiModifier.VOLATILE)) {
|
||||
stateBefore.setVarValue(var, dfaSource);
|
||||
}
|
||||
stateBefore.setVarValue(var, dfaSource);
|
||||
if (DfaNullability.fromDfType(var.getInherentType()) == DfaNullability.NULLABLE &&
|
||||
DfaNullability.fromDfType(stateBefore.getDfType(var)) == DfaNullability.UNKNOWN && isVariableInitializer()) {
|
||||
stateBefore.meetDfType(var, DfaNullability.NULLABLE.asDfType());
|
||||
}
|
||||
}
|
||||
|
||||
pushResult(interpreter, stateBefore, dfaDest);
|
||||
pushResult(interpreter, stateBefore, dfaDest instanceof DfaVariableValue ? dfaDest : dfaSource);
|
||||
return nextStates(interpreter, stateBefore);
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,10 @@
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
class Scratch {
|
||||
private volatile @Nullable String foo;
|
||||
|
||||
public @NotNull String foo() {
|
||||
return this.foo = "bar";
|
||||
}
|
||||
}
|
||||
@@ -744,4 +744,5 @@ public class DataFlowInspectionTest extends DataFlowInspectionTestCase {
|
||||
public void testNullWarningAfterInstanceofAndNullCheck() { doTest(); }
|
||||
public void testInitializedViaSuperCall() { doTest(); }
|
||||
public void testBoxedBooleanMethodWithCast() { doTest(); }
|
||||
public void testAssignAndReturnVolatile() { doTest(); }
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user