From 3aeea9457459a94edd6c520ff6bac130fc761df8 Mon Sep 17 00:00:00 2001 From: Anna Kozlova Date: Tue, 21 May 2019 17:34:26 +0200 Subject: [PATCH] collect unhandled exceptions: process captured wildcards (IDEA-214559) GitOrigin-RevId: d0a59dd9e5f43e5265584f5a8a06702334343d1a --- .../src/com/intellij/codeInsight/ExceptionUtil.java | 3 +++ .../advHighlighting7/PreciseRethrowCaptured.java | 13 +++++++++++++ .../daemon/LightAdvHighlightingJdk7Test.java | 1 + 3 files changed, 17 insertions(+) create mode 100644 java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting7/PreciseRethrowCaptured.java diff --git a/java/java-psi-impl/src/com/intellij/codeInsight/ExceptionUtil.java b/java/java-psi-impl/src/com/intellij/codeInsight/ExceptionUtil.java index e1979f8cdf86..d3e0a2a0402f 100644 --- a/java/java-psi-impl/src/com/intellij/codeInsight/ExceptionUtil.java +++ b/java/java-psi-impl/src/com/intellij/codeInsight/ExceptionUtil.java @@ -208,6 +208,9 @@ public class ExceptionUtil { List result = new ArrayList<>(); for (PsiType type : referenceTypes) { type = PsiClassImplUtil.correctType(substitutor.substitute(type), scope); + if (type instanceof PsiCapturedWildcardType) { + type = ((PsiCapturedWildcardType)type).getUpperBound(); + } if (type instanceof PsiClassType) { result.add((PsiClassType)type); } diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting7/PreciseRethrowCaptured.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting7/PreciseRethrowCaptured.java new file mode 100644 index 000000000000..6f42c94fc594 --- /dev/null +++ b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting7/PreciseRethrowCaptured.java @@ -0,0 +1,13 @@ +class ErrorTest { + public static void rethrow(Thrower thrower) { + try { + thrower.doThrow(); + } + catch (Throwable e) { + throw e; + } + } + interface Thrower { + void doThrow() throws E; + } +} \ No newline at end of file diff --git a/java/java-tests/testSrc/com/intellij/java/codeInsight/daemon/LightAdvHighlightingJdk7Test.java b/java/java-tests/testSrc/com/intellij/java/codeInsight/daemon/LightAdvHighlightingJdk7Test.java index ad4f9d94cc2c..cc6296734c0f 100644 --- a/java/java-tests/testSrc/com/intellij/java/codeInsight/daemon/LightAdvHighlightingJdk7Test.java +++ b/java/java-tests/testSrc/com/intellij/java/codeInsight/daemon/LightAdvHighlightingJdk7Test.java @@ -121,6 +121,7 @@ public class LightAdvHighlightingJdk7Test extends LightDaemonAnalyzerTestCase { public void testUncheckedGenericsArrayCreation() { doTest(true, false); } public void testGenericsArrayCreation() { doTest(false, false); } public void testPreciseRethrow() { doTest(false, false); } + public void testPreciseRethrowCaptured() { doTest(false, false); } public void testPreciseRethrowNonAssignableToException() { doTest(false, false); } public void testPreciseRethrowOfOneExceptionInTheBlock() { doTest(false, false); } public void testPreciseRethrowWithRuntimeExceptionDeclared() { doTest(false, false); }