diff --git a/java/java-analysis-impl/src/com/intellij/codeInspection/dataFlow/NullParameterConstraintChecker.java b/java/java-analysis-impl/src/com/intellij/codeInspection/dataFlow/NullParameterConstraintChecker.java index e5c4f4fcac9d..218656cfb91d 100644 --- a/java/java-analysis-impl/src/com/intellij/codeInspection/dataFlow/NullParameterConstraintChecker.java +++ b/java/java-analysis-impl/src/com/intellij/codeInspection/dataFlow/NullParameterConstraintChecker.java @@ -79,10 +79,6 @@ class NullParameterConstraintChecker extends DataFlowRunner { @NotNull @Override protected DfaInstructionState[] acceptInstruction(@NotNull InstructionVisitor visitor, @NotNull DfaInstructionState instructionState) { - DfaMemoryState memState = instructionState.getMemoryState(); - if (memState.isEphemeral()) { - return DfaInstructionState.EMPTY_ARRAY; - } Instruction instruction = instructionState.getInstruction(); if (instruction instanceof AssignInstruction) { @@ -96,6 +92,7 @@ class NullParameterConstraintChecker extends DataFlowRunner { } if (instruction instanceof ReturnInstruction && !((ReturnInstruction)instruction).isViaException()) { + DfaMemoryState memState = instructionState.getMemoryState(); for (PsiParameter parameter : myPossiblyViolatedParameters.toArray(new PsiParameter[myPossiblyViolatedParameters.size()])) { final DfaVariableValue dfaVar = getFactory().getVarFactory().createVariableValue(parameter, false); if (!memState.isNotNull(dfaVar)) { diff --git a/java/java-tests/testData/inspection/dataFlow/fixture/NullLiteralAndInferredMethodContract.java b/java/java-tests/testData/inspection/dataFlow/fixture/NullLiteralAndInferredMethodContract.java new file mode 100644 index 000000000000..8be1e9e8a7d4 --- /dev/null +++ b/java/java-tests/testData/inspection/dataFlow/fixture/NullLiteralAndInferredMethodContract.java @@ -0,0 +1,17 @@ +class NullLiteralAndInferredMethodContract { + { + initExpressionConstraints(null); + } + + public void initExpressionConstraints(Object parent) { + String currentProperties = getCurrentProperties(parent); + System.out.println(currentProperties != null ? currentProperties : ""); + } + + private String getCurrentProperties(Object parent) { + if (parent instanceof String) { + return ((String) parent).substring(1); + } + return null; + } +} \ No newline at end of file diff --git a/java/java-tests/testSrc/com/intellij/codeInspection/DataFlowInspectionTest.java b/java/java-tests/testSrc/com/intellij/codeInspection/DataFlowInspectionTest.java index e4ad15969725..8d3e4c50b620 100644 --- a/java/java-tests/testSrc/com/intellij/codeInspection/DataFlowInspectionTest.java +++ b/java/java-tests/testSrc/com/intellij/codeInspection/DataFlowInspectionTest.java @@ -400,4 +400,9 @@ public class DataFlowInspectionTest extends DataFlowInspectionTestCase { doTest(); myFixture.findSingleIntention("Remove 'if' statement"); } + + //https://youtrack.jetbrains.com/issue/IDEA-162184 + public void testNullLiteralAndInferredMethodContract() { + doTest(); + } }