mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
null argument checker: initialize memory state with nullable parameter states IDEA-162816
This commit is contained in:
+6
-1
@@ -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) {
|
||||
|
||||
+13
@@ -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();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user