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 b1839e95b0cb..a341ae7103c2 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 @@ -79,7 +79,7 @@ public class TypeCastInstruction extends ExpressionPushingInstruction { List result = new ArrayList<>(); if (myTransferValue != null) { DfaMemoryState castFail = stateBefore.createCopy(); - if (fromType != null && myCastTo.isConvertibleFrom(fromType)) { + if (fromType != null && (!constraint.isResolved() || myCastTo.isConvertibleFrom(fromType))) { if (!castTopOfStack(factory, stateBefore, constraint)) { castPossible = false; } else { diff --git a/java/java-tests/testData/inspection/dataFlow/unreachableCode/UnresolvedCast.java b/java/java-tests/testData/inspection/dataFlow/unreachableCode/UnresolvedCast.java new file mode 100644 index 000000000000..dc7405688da4 --- /dev/null +++ b/java/java-tests/testData/inspection/dataFlow/unreachableCode/UnresolvedCast.java @@ -0,0 +1,11 @@ + +class Test { + void test(Object obj) { + try { + System.out.println((MyUnresolvedClass)obj); + System.out.println("hello"); + } catch (Exception e) { + throw new RuntimeException(e); + } + } +} \ 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 36393274c446..620942718e57 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 @@ -41,6 +41,8 @@ public class UnreachableCodeInspectionTest extends LightJavaCodeInsightFixtureTe public void testLambdaCast() { doTest(); } public void testFailingCast() { doTest(); } + + public void testUnresolvedCast() { doTest(); } private void doTest() { myFixture.configureByFile(getTestName(false) + ".java");