redundant throws: filter out unchecked exception (IDEA-177478, IDEA-177506)

This commit is contained in:
Dmitry Batkovich
2017-08-14 10:46:42 +03:00
parent 4232f8dd41
commit 7fb26c249d
2 changed files with 9 additions and 1 deletions

View File

@@ -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);

View File

@@ -0,0 +1,7 @@
// "Remove 'RuntimeException' from 'f' throws list" "false"
import java.io.*;
class a {
void f() throws <caret>RuntimeException {
}
}