Removed special handling of getX() != null

Also fixes IDEABKL-7233 if methods are annotated as pure
This commit is contained in:
Tagir Valeev
2018-01-03 16:38:16 +07:00
parent 14c9180131
commit 282e4ff321
4 changed files with 41 additions and 6 deletions
@@ -942,11 +942,6 @@ public class DfaMemoryStateImpl implements DfaMemoryState {
final boolean containsCalls = dfaLeft instanceof DfaVariableValue && ((DfaVariableValue)dfaLeft).containsCalls();
// track "x" property state only inside "if (getX() != null) ..."
if (containsCalls && !isNotNull(dfaLeft) && isNull(dfaRight) && !isNegated) {
return true;
}
if (dfaLeft == dfaRight) {
return containsCalls || !isNegated;
}
@@ -12,10 +12,11 @@ class Doo {
boolean pureSomething() { return false;}
public void main2() {
// isSomething is non-pure: flush
if (getMethod() == null && !isSomething()) {
return;
} else {
System.out.println(getMethod().<warning descr="Method invocation 'hashCode' may produce 'java.lang.NullPointerException'">hashCode</warning>());
System.out.println(getMethod().hashCode());
}
}
@@ -0,0 +1,38 @@
import org.jetbrains.annotations.Contract;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
// IDEABKL7233
public class XorNullity {
void test(CreateForm createForm) {
if(createForm.getOpenIdIdentity() == null ^ createForm.getOpenIdProvider() == null) {
throw new RuntimeException("Invalid request");
}
if(createForm.getOpenIdIdentity() != null) {
findByOpenIdIdentity(createForm.getOpenIdProvider()); // never null
}
}
void test2(CreateForm createForm) {
if(createForm.getOpenIdIdentity() == null ^ createForm.getOpenIdProvider() != null) {
throw new RuntimeException("Invalid request");
}
if(createForm.getOpenIdIdentity() != null) {
findByOpenIdIdentity(<warning descr="Argument 'createForm.getOpenIdProvider()' might be null">createForm.getOpenIdProvider()</warning>); // nullable
}
}
void findByOpenIdIdentity(@NotNull Object identity) {}
interface CreateForm {
@Nullable
@Contract(pure = true)
Object getOpenIdIdentity();
@Nullable
@Contract(pure = true)
Object getOpenIdProvider();
}
}
@@ -578,4 +578,5 @@ public class DataFlowInspectionTest extends DataFlowInspectionTestCase {
public void testManyBooleans() { doTest(); }
public void testPureNoArgMethodAsVariable() { doTest(); }
public void testRedundantAssignment() { doTest(); }
public void testXorNullity() { doTest(); }
}