volatile field's nullity shouldn't be used for dfa (IDEA-64696)

This commit is contained in:
peter
2011-01-27 19:36:59 +01:00
parent f9ae15b894
commit 6c8b65e4cd
4 changed files with 55 additions and 1 deletions
@@ -92,7 +92,9 @@ public class StandardInstructionVisitor extends InstructionVisitor {
onAssigningToNotNullableVariable(instruction, runner);
}
}
memState.setVarValue(var, dfaSource);
if (!(psiVariable instanceof PsiField) || !psiVariable.hasModifierProperty(PsiModifier.VOLATILE)) {
memState.setVarValue(var, dfaSource);
}
}
memState.push(dfaDest);
@@ -0,0 +1,26 @@
import javax.swing.*;
class Test {
public void setObj(Object obj) {
this.obj = obj;
}
public void test() {
obj = new Object();
javax.swing.SwingUtilities.invokeLater(new Runnable() {
public void run() {
Object o = obj;
if (o != null) {
System.out.println("x");
}
}
});
final Object u = new Object();
if (<warning descr="Condition 'u != null' is always 'true'">u != null</warning>) {
System.out.println("y");
}
obj = null;
}
private volatile Object obj;
}
@@ -0,0 +1,24 @@
import org.jetbrains.annotations.NotNull;
import javax.swing.*;
class Test {
public void setObj(Object obj) {
this.obj = obj;
}
public void test() {
obj = new Object();
SwingUtilities.invokeLater(new Runnable() {
public void run() {
Object o = obj;
if (<warning descr="Condition 'o != null' is always 'true'">o != null</warning>) {
System.out.println("x");
}
}
});
obj = <warning descr="'null' is assigned to a variable that is annotated with @NotNull">null</warning>;
}
@NotNull private volatile Object obj;
}
@@ -29,5 +29,7 @@ public class DataFlowInspectionFixtureTest extends JavaCodeInsightFixtureTestCas
public void testTryInAnonymous() throws Throwable { doTest(); }
public void testNullableAnonymousMethod() throws Throwable { doTest(); }
public void testNullableAnonymousParameter() throws Throwable { doTest(); }
public void testNullableAnonymousVolatile() throws Throwable { doTest(); }
public void testNullableAnonymousVolatileNotNull() throws Throwable { doTest(); }
}