null argument checker: initialize memory state with nullable parameter states IDEA-162816

This commit is contained in:
Dmitry Batkovich
2016-10-20 18:43:37 +03:00
parent 4e0aa95bf7
commit e892ed03fa
3 changed files with 22 additions and 1 deletions
@@ -33,6 +33,7 @@ import gnu.trove.THashSet;
import org.jetbrains.annotations.NotNull;
import java.util.Collection;
import java.util.Collections;
import java.util.Set;
/**
@@ -83,7 +84,6 @@ class NullParameterConstraintChecker extends DataFlowRunner {
@Override
protected DfaInstructionState[] acceptInstruction(@NotNull InstructionVisitor visitor, @NotNull DfaInstructionState instructionState) {
Instruction instruction = instructionState.getInstruction();
if (instruction instanceof PushInstruction) {
final DfaValue var = ((PushInstruction)instruction).getValue();
if (var instanceof DfaVariableValue) {
@@ -127,6 +127,11 @@ class NullParameterConstraintChecker extends DataFlowRunner {
protected MyDfaMemoryState(DfaValueFactory factory) {
super(factory);
for (PsiParameter parameter : myPossiblyViolatedParameters) {
setVariableState(getFactory().getVarFactory().createVariableValue(parameter, false), new DfaVariableState(Collections.emptySet(),
Collections.emptySet(),
Nullness.NULLABLE));
}
}
protected MyDfaMemoryState(MyDfaMemoryState toCopy) {
@@ -0,0 +1,13 @@
import java.util.Collections;
class Test {
private static String useAndReturnValue(final String result) {
Collections.singleton(result);
return result;
}
void m() {
useAndReturnValue(<warning descr="Passing 'null' argument to non annotated parameter">null</warning>);
}
}
@@ -407,4 +407,7 @@ public class DataFlowInspectionTest extends DataFlowInspectionTestCase {
doTest();
}
public void testNullLiteralArgumentDoesntReportedWhenMethodOnlyThrowAnException() { doTest(); }
public void testNullLiteralArgumentValueUsedAsReturnValue() {
doTest();
}
}