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 996135bc13d5..6e147abc5765 100644 --- a/java/java-psi-impl/src/com/intellij/codeInsight/ExceptionUtil.java +++ b/java/java-psi-impl/src/com/intellij/codeInsight/ExceptionUtil.java @@ -612,12 +612,20 @@ public class ExceptionUtil { for (PsiType type : getPreciseThrowTypes(throwStatement.getException())) { List types = type instanceof PsiDisjunctionType ? ((PsiDisjunctionType)type).getDisjunctions() : Collections.singletonList(type); for (PsiType subType : types) { + PsiClassType classType = null; if (subType instanceof PsiClassType) { - PsiClassType classType = (PsiClassType)subType; - if (!isUncheckedException(classType) && !isHandled(throwStatement, classType, topElement)) { - unhandled.add(classType); + classType = (PsiClassType)subType; + } + else if (subType instanceof PsiCapturedWildcardType) { + PsiType upperBound = ((PsiCapturedWildcardType)subType).getUpperBound(); + if (upperBound instanceof PsiClassType) { + classType = (PsiClassType)upperBound; } } + + if (classType != null && !isUncheckedException(classType) && !isHandled(throwStatement, classType, topElement)) { + unhandled.add(classType); + } } } return unhandled; diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/exceptionHighlighting/CapturedWildcardInReturn.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/exceptionHighlighting/CapturedWildcardInReturn.java new file mode 100644 index 000000000000..561d60c93a0e --- /dev/null +++ b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/exceptionHighlighting/CapturedWildcardInReturn.java @@ -0,0 +1,7 @@ +import java.util.function.Supplier; + +class MyTest { + public static void main(Supplier supplierException) { + throw supplierException.get(); + } +} diff --git a/java/java-tests/testSrc/com/intellij/java/codeInsight/daemon/lambda/UnhandledExceptionsHighlightingTest.kt b/java/java-tests/testSrc/com/intellij/java/codeInsight/daemon/lambda/UnhandledExceptionsHighlightingTest.kt new file mode 100644 index 000000000000..17a801425f20 --- /dev/null +++ b/java/java-tests/testSrc/com/intellij/java/codeInsight/daemon/lambda/UnhandledExceptionsHighlightingTest.kt @@ -0,0 +1,22 @@ +// Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. +package com.intellij.java.codeInsight.daemon.lambda + +import com.intellij.codeInsight.daemon.LightDaemonAnalyzerTestCase +import com.intellij.openapi.projectRoots.JavaSdkVersion +import com.intellij.openapi.roots.LanguageLevelProjectExtension +import com.intellij.pom.java.LanguageLevel +import com.intellij.testFramework.IdeaTestUtil + +class UnhandledExceptionsHighlightingTest : LightDaemonAnalyzerTestCase() { + + fun testCapturedWildcardInReturn() { + doTest(false) + } + + private fun doTest(warnings: Boolean) { + LanguageLevelProjectExtension.getInstance(getJavaFacade().project).languageLevel = LanguageLevel.JDK_1_8 + IdeaTestUtil.setTestVersion(JavaSdkVersion.JDK_1_8, getModule(), testRootDisposable) + doTest("""/codeInsight/daemonCodeAnalyzer/exceptionHighlighting/${getTestName(false)}.java""", warnings, false) + } + +}