mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-05-06 05:10:22 +07:00
precise rethrow with multiple exceptions in the try block (IDEA-169273)
This commit is contained in:
@@ -124,15 +124,11 @@ public class PsiCatchSectionImpl extends CompositePsiElement implements PsiCatch
|
||||
return thrownType;
|
||||
});
|
||||
// ... and T is assignable to Ej ...
|
||||
boolean passed = true;
|
||||
for (PsiType type : uncaughtTypes) {
|
||||
if (!declaredType.isAssignableFrom(type) && !(type instanceof PsiClassType && ExceptionUtil.isUncheckedException((PsiClassType)type))) {
|
||||
passed = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
// ... the throw statement throws precisely the set of exception types T.
|
||||
if (passed) return uncaughtTypes;
|
||||
if (uncaughtTypes.stream().anyMatch(type -> declaredType.isAssignableFrom(type) ||
|
||||
type instanceof PsiClassType && ExceptionUtil.isUncheckedException((PsiClassType)type))) {
|
||||
return uncaughtTypes;
|
||||
}
|
||||
}
|
||||
|
||||
return Collections.singletonList(declaredType);
|
||||
|
||||
@@ -0,0 +1,20 @@
|
||||
|
||||
class A1 extends Exception {}
|
||||
|
||||
class A2 extends Exception {}
|
||||
|
||||
class BA1 extends A1 {}
|
||||
|
||||
class ErrorTest {
|
||||
public void testNok(boolean mode) throws BA1, A2 {
|
||||
try {
|
||||
if (mode) {
|
||||
throw new BA1();
|
||||
} else {
|
||||
throw new A2();
|
||||
}
|
||||
} catch (A1 ex) {
|
||||
throw ex;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -141,6 +141,7 @@ public class LightAdvHighlightingJdk7Test extends LightDaemonAnalyzerTestCase {
|
||||
public void testGenericsArrayCreation() { doTest(false, false); }
|
||||
public void testPreciseRethrow() { doTest(false, false); }
|
||||
public void testPreciseRethrowNonAssignableToException() { doTest(false, false); }
|
||||
public void testPreciseRethrowOfOneExceptionInTheBlock() { doTest(false, false); }
|
||||
public void testImprovedCatchAnalysis() { doTest(true, false); }
|
||||
public void testPolymorphicTypeCast() { doTest(true, false); }
|
||||
public void testTypeCastInInstanceof() { doTest(true, false); }
|
||||
|
||||
Reference in New Issue
Block a user