mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
unchecked exceptions: check captured wildcards (IDEA-189184)
This commit is contained in:
@@ -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;
|
||||
|
||||
+7
@@ -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>
|
||||
}
|
||||
}
|
||||
+22
@@ -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)
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user