precise rethrow with multiple exceptions in the try block (IDEA-169273)

This commit is contained in:
Anna.Kozlova
2017-03-07 17:12:05 +01:00
parent dd2da88977
commit 71cc26e25c
3 changed files with 25 additions and 8 deletions

View File

@@ -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);

View File

@@ -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;
}
}
}

View File

@@ -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); }