unchecked exceptions: check captured wildcards (IDEA-189184)

This commit is contained in:
Anna.Kozlova
2018-04-03 16:53:09 +02:00
parent c8493f4064
commit 5ecee5486b
3 changed files with 40 additions and 3 deletions
@@ -612,12 +612,20 @@ public class ExceptionUtil {
for (PsiType type : getPreciseThrowTypes(throwStatement.getException())) {
List<PsiType> 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;
@@ -0,0 +1,7 @@
import java.util.function.Supplier;
class MyTest {
public static void main(Supplier<? extends Exception> supplierException) {
<error descr="Unhandled exception: java.lang.Exception">throw supplierException.get();</error>
}
}
@@ -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)
}
}