diff --git a/java/java-analysis-impl/src/com/intellij/codeInspection/unneededThrows/RedundantThrowsDeclarationLocalInspection.java b/java/java-analysis-impl/src/com/intellij/codeInspection/unneededThrows/RedundantThrowsDeclarationLocalInspection.java index 925d56efae87..ae302dfbee8e 100644 --- a/java/java-analysis-impl/src/com/intellij/codeInspection/unneededThrows/RedundantThrowsDeclarationLocalInspection.java +++ b/java/java-analysis-impl/src/com/intellij/codeInspection/unneededThrows/RedundantThrowsDeclarationLocalInspection.java @@ -15,6 +15,7 @@ */ package com.intellij.codeInspection.unneededThrows; +import com.intellij.codeInsight.ExceptionUtil; import com.intellij.codeInsight.daemon.JavaErrorMessages; import com.intellij.codeInsight.daemon.impl.analysis.JavaHighlightUtil; import com.intellij.codeInsight.daemon.impl.quickfix.MethodThrowsFix; @@ -135,7 +136,7 @@ public class RedundantThrowsDeclarationLocalInspection extends BaseJavaBatchLoca .of(method.getThrowsList().getReferenceElements()) .map(ref -> { PsiElement resolved = ref.resolve(); - return resolved instanceof PsiClass ? new ReferenceAndType(ref) : null; + return resolved instanceof PsiClass && !ExceptionUtil.isUncheckedException((PsiClass)resolved) ? new ReferenceAndType(ref) : null; }) .filter(Objects::nonNull) .toArray(ReferenceAndType[]::new); diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/methodThrows/beforeUncheckedException.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/methodThrows/beforeUncheckedException.java new file mode 100644 index 000000000000..149bc7f0f4d0 --- /dev/null +++ b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/methodThrows/beforeUncheckedException.java @@ -0,0 +1,7 @@ +// "Remove 'RuntimeException' from 'f' throws list" "false" +import java.io.*; + +class a { + void f() throws RuntimeException { + } +}