let method calls on other instances not affect our fields (IDEA-92380)

This commit is contained in:
peter
2013-02-03 22:42:57 +01:00
parent b418e60060
commit aa671e4c3f
7 changed files with 38 additions and 6 deletions
@@ -1254,7 +1254,11 @@ class ControlFlowAnalyzer extends JavaElementVisitor {
}
}
addInstruction(new MethodCallInstruction(expression, createChainedVariableValue(expression)));
MethodCallInstruction callInstruction = new MethodCallInstruction(expression, createChainedVariableValue(expression));
if (!DfaValueFactory.isEffectivelyUnqualified(methodExpression)) {
callInstruction.setShouldFlushFields(false);
}
addInstruction(callInstruction);
if (!myCatchStack.isEmpty()) {
addMethodThrows(expression.resolveMethod());
@@ -72,6 +72,10 @@ public class MethodCallInstruction extends Instruction {
}
}
public void setShouldFlushFields(boolean shouldFlushFields) {
myShouldFlushFields = shouldFlushFields;
}
@Nullable
public PsiType getResultType() {
return myType;
@@ -154,7 +154,7 @@ public class DfaValueFactory {
return null;
}
private static boolean isEffectivelyUnqualified(PsiReferenceExpression refExpression) {
public static boolean isEffectivelyUnqualified(PsiReferenceExpression refExpression) {
PsiExpression qualifier = refExpression.getQualifierExpression();
if (qualifier == null) {
return true;
@@ -0,0 +1,22 @@
class DefaultObjectIdentifier {
String user;
String requestorClass;
public boolean equals(Object otherObject) {
if (otherObject == null || !(otherObject instanceof DefaultObjectIdentifier))
return false;
else {
DefaultObjectIdentifier identifier = (DefaultObjectIdentifier) otherObject;
if (user == null && identifier.user != null)
return false;
else if (requestorClass == null && identifier.requestorClass != null)
return false;
else if (((user == null && <warning descr="Condition 'identifier.user == null' is always 'true' when reached">identifier.user == null</warning>)
|| (this.user.equals(identifier.user)))
&&
((requestorClass == null && <warning descr="Condition 'identifier.requestorClass == null' is always 'true' when reached">identifier.requestorClass == null</warning>)
|| this.requestorClass.equals(identifier.requestorClass)))
return true;
else
return false;
}
}}
@@ -54,12 +54,12 @@ class Foo {
System.out.println(data.hashCode());
}
void dontWarnWhenDoubleChecked_This_WithMethodCall() {
void warnWhenDoubleChecked_This_WithMethodCall() {
if (data == null) {
return;
}
System.out.println(data.hashCode());
if (data == null) {
if (<warning descr="Condition 'data == null' is always 'false'">data == null</warning>) {
return;
}
System.out.println(data.hashCode());
@@ -56,12 +56,12 @@ class Foo {
System.out.println(data.hashCode());
}
void dontWarnWhenDoubleChecked_This_WithMethodCall() {
void warnWhenDoubleChecked_This_WithMethodCall() {
if (data == null) {
return;
}
System.out.println(data.hashCode());
if (data == null) {
if (<warning descr="Condition 'data == null' is always 'false'">data == null</warning>) {
return;
}
System.out.println(data.hashCode());
@@ -156,4 +156,6 @@ public class DataFlowInspectionTest extends LightCodeInsightFixtureTestCase {
public void testTryWithResourcesInstanceOf() { doTest(); }
public void testOmnipresentExceptions() { doTest(); }
public void testEqualsHasNoSideEffects() { doTest(); }
}