From 7678df1cbbfa73fcd76e132fd90e5996aed4c9ec Mon Sep 17 00:00:00 2001 From: anna Date: Thu, 5 Jul 2012 12:07:47 +0200 Subject: [PATCH] IDEA-87652 --- .../dataFlow/DfaMemoryStateImpl.java | 2 +- .../NullableProblemThroughCast/expected.xml | 8 ++++++++ .../NullableProblemThroughCast/src/Npe.java | 18 ++++++++++++++++++ .../codeInspection/DataFlowInspectionTest.java | 1 + 4 files changed, 28 insertions(+), 1 deletion(-) create mode 100644 java/java-tests/testData/inspection/dataFlow/NullableProblemThroughCast/expected.xml create mode 100644 java/java-tests/testData/inspection/dataFlow/NullableProblemThroughCast/src/Npe.java diff --git a/java/java-impl/src/com/intellij/codeInspection/dataFlow/DfaMemoryStateImpl.java b/java/java-impl/src/com/intellij/codeInspection/dataFlow/DfaMemoryStateImpl.java index 718fc2c8b861..b38fa364fa43 100644 --- a/java/java-impl/src/com/intellij/codeInspection/dataFlow/DfaMemoryStateImpl.java +++ b/java/java-impl/src/com/intellij/codeInspection/dataFlow/DfaMemoryStateImpl.java @@ -540,7 +540,7 @@ public class DfaMemoryStateImpl implements DfaMemoryState { DfaTypeValue dfaType = (DfaTypeValue)dfaCond.getRightOperand(); final DfaVariableState varState = getVariableState(dfaVar); - varState.setNullable(dfaType.isNullable()); + varState.setNullable(varState.isNullable() || dfaType.isNullable()); return !isNotNull(dfaVar) || varState.setInstanceofValue(dfaType); } diff --git a/java/java-tests/testData/inspection/dataFlow/NullableProblemThroughCast/expected.xml b/java/java-tests/testData/inspection/dataFlow/NullableProblemThroughCast/expected.xml new file mode 100644 index 000000000000..b7eb5e8e80a8 --- /dev/null +++ b/java/java-tests/testData/inspection/dataFlow/NullableProblemThroughCast/expected.xml @@ -0,0 +1,8 @@ + + + + Npe.java + 6 + Method invocation <code>((SomeInterfaceImpl)x).bar()</code> may produce <code>java.lang.NullPointerException</code> + + diff --git a/java/java-tests/testData/inspection/dataFlow/NullableProblemThroughCast/src/Npe.java b/java/java-tests/testData/inspection/dataFlow/NullableProblemThroughCast/src/Npe.java new file mode 100644 index 000000000000..5937591e0b70 --- /dev/null +++ b/java/java-tests/testData/inspection/dataFlow/NullableProblemThroughCast/src/Npe.java @@ -0,0 +1,18 @@ +import org.jetbrains.annotations.Nullable; + +public class Npe { + + void foo(@Nullable SomeInterface x) { + ((SomeInterfaceImpl)x).bar(); + } + + interface SomeInterface { + void bar(); + } + + class SomeInterfaceImpl implements SomeInterface { + @Override + public void bar() { + } + } +} \ 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 6e6ed040da94..7aff8dad846d 100644 --- a/java/java-tests/testSrc/com/intellij/codeInspection/DataFlowInspectionTest.java +++ b/java/java-tests/testSrc/com/intellij/codeInspection/DataFlowInspectionTest.java @@ -96,6 +96,7 @@ public class DataFlowInspectionTest extends InspectionTestCase { public void testNullable() throws Exception { doTest15(); } public void testNullableThroughCast() throws Exception { doTest15(); } + public void testNullableProblemThroughCast() throws Exception { doTest15(); } public void testNullableThroughVariable() throws Exception { doTest15(); } public void testNullableThroughVariableShouldNotBeReported() throws Exception { doTest15(); } public void testNullableAssignment() throws Exception { doTest15(); }