diff --git a/java/java-analysis-impl/src/com/intellij/codeInspection/dataFlow/java/inst/TypeCastInstruction.java b/java/java-analysis-impl/src/com/intellij/codeInspection/dataFlow/java/inst/TypeCastInstruction.java index 884323966712..4edaeba0d2dc 100644 --- a/java/java-analysis-impl/src/com/intellij/codeInspection/dataFlow/java/inst/TypeCastInstruction.java +++ b/java/java-analysis-impl/src/com/intellij/codeInspection/dataFlow/java/inst/TypeCastInstruction.java @@ -103,7 +103,9 @@ public class TypeCastInstruction extends ExpressionPushingInstruction { } } - result.add(nextState(interpreter, stateBefore)); + if (castPossible) { + result.add(nextState(interpreter, stateBefore)); + } pushResult(interpreter, stateBefore, stateBefore.pop()); } UnsatisfiedConditionProblem problem = getConditionProblem(); diff --git a/java/java-tests/testData/inspection/dataFlow/unreachableCode/FailingCast.java b/java/java-tests/testData/inspection/dataFlow/unreachableCode/FailingCast.java new file mode 100644 index 000000000000..ca271334befb --- /dev/null +++ b/java/java-tests/testData/inspection/dataFlow/unreachableCode/FailingCast.java @@ -0,0 +1,8 @@ + +class Test { + public static void main(String[] args) { + Object o = "12"; + Integer a = (Integer) o; + System.out.println("1"); + } +} \ No newline at end of file diff --git a/java/java-tests/testSrc/com/intellij/java/codeInspection/dataFlow/UnreachableCodeInspectionTest.java b/java/java-tests/testSrc/com/intellij/java/codeInspection/dataFlow/UnreachableCodeInspectionTest.java index 15390325f7ff..36393274c446 100644 --- a/java/java-tests/testSrc/com/intellij/java/codeInspection/dataFlow/UnreachableCodeInspectionTest.java +++ b/java/java-tests/testSrc/com/intellij/java/codeInspection/dataFlow/UnreachableCodeInspectionTest.java @@ -39,6 +39,8 @@ public class UnreachableCodeInspectionTest extends LightJavaCodeInsightFixtureTe public void testCatchLinkageError() { doTest(); } public void testLambdaCast() { doTest(); } + + public void testFailingCast() { doTest(); } private void doTest() { myFixture.configureByFile(getTestName(false) + ".java");