diff --git a/java/java-psi-impl/src/com/intellij/psi/impl/source/tree/java/PsiCatchSectionImpl.java b/java/java-psi-impl/src/com/intellij/psi/impl/source/tree/java/PsiCatchSectionImpl.java index 69a39cc64901..3f97d91fdfae 100644 --- a/java/java-psi-impl/src/com/intellij/psi/impl/source/tree/java/PsiCatchSectionImpl.java +++ b/java/java-psi-impl/src/com/intellij/psi/impl/source/tree/java/PsiCatchSectionImpl.java @@ -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); diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting7/PreciseRethrowOfOneExceptionInTheBlock.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting7/PreciseRethrowOfOneExceptionInTheBlock.java new file mode 100644 index 000000000000..a8bd8e6a7a1d --- /dev/null +++ b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting7/PreciseRethrowOfOneExceptionInTheBlock.java @@ -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; + } + } +} \ No newline at end of file diff --git a/java/java-tests/testSrc/com/intellij/codeInsight/daemon/LightAdvHighlightingJdk7Test.java b/java/java-tests/testSrc/com/intellij/codeInsight/daemon/LightAdvHighlightingJdk7Test.java index 16a89be8eac9..4e4ead573d2d 100644 --- a/java/java-tests/testSrc/com/intellij/codeInsight/daemon/LightAdvHighlightingJdk7Test.java +++ b/java/java-tests/testSrc/com/intellij/codeInsight/daemon/LightAdvHighlightingJdk7Test.java @@ -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); }