mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
Java: Don't report the catch section as unreachable where a subclass of declared exception can be thrown (IDEA-175863)
This commit is contained in:
+2
-1
@@ -1387,7 +1387,8 @@ public class HighlightUtil extends HighlightUtilBase {
|
||||
if (ExceptionUtil.isGeneralExceptionType(catchType)) continue;
|
||||
|
||||
// collect exceptions which are caught by this type
|
||||
Collection<PsiClassType> caught = ContainerUtil.findAll(thrownTypes, catchType::isAssignableFrom);
|
||||
final Collection<PsiClassType> caught =
|
||||
ContainerUtil.findAll(thrownTypes, type -> catchType.isAssignableFrom(type) || type.isAssignableFrom(catchType));
|
||||
if (caught.isEmpty()) continue;
|
||||
final Collection<PsiClassType> caughtCopy = ContainerUtil.newHashSet(caught);
|
||||
|
||||
|
||||
+23
@@ -0,0 +1,23 @@
|
||||
class C {
|
||||
void foo(boolean b) throws Exception {
|
||||
try {
|
||||
if (b) {
|
||||
throw new ChildException();
|
||||
} else {
|
||||
method();
|
||||
}
|
||||
} catch (ChildException e) {
|
||||
System.out.println("child");
|
||||
} catch (ParentException e) {
|
||||
System.out.println("parent");
|
||||
}
|
||||
}
|
||||
|
||||
private static void method() throws Exception {
|
||||
throw new ParentException();
|
||||
}
|
||||
|
||||
static class ParentException extends Exception { }
|
||||
|
||||
static class ChildException extends ParentException { }
|
||||
}
|
||||
+1
@@ -186,6 +186,7 @@ public class LightAdvHighlightingJdk7Test extends LightDaemonAnalyzerTestCase {
|
||||
public void testIDEA138978() { doTest(false, false); }
|
||||
public void testIntersectionTypeCast() { doTest(false, false); }
|
||||
public void testUsedMethodCalledViaReflectionInTheSameFile() { doTest(true, false); }
|
||||
public void testCatchSubclassOfThrownException() { doTest(true, false); }
|
||||
|
||||
public void testArrayInitializerTypeCheckVariableType() { doTest(false, false);}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user