From 6320d5f50c6d2cd6126de4f9e24cc28886c00b4d Mon Sep 17 00:00:00 2001 From: Anna Kozlova Date: Tue, 21 Jan 2014 18:10:02 +0400 Subject: [PATCH] do not replace checked exception with unchecked (IDEA-119345) --- .../intellij/codeInsight/ExceptionUtil.java | 14 +++++++++---- ...SuperMethodsInMultipleOverridingCheck.java | 21 +++++++++++++++++++ .../daemon/LightAdvHighlightingTest.java | 1 + 3 files changed, 32 insertions(+), 4 deletions(-) create mode 100644 java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting/IgnoreSuperMethodsInMultipleOverridingCheck.java 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 11de0435a41d..d9ec369b4199 100644 --- a/java/java-psi-impl/src/com/intellij/codeInsight/ExceptionUtil.java +++ b/java/java-psi-impl/src/com/intellij/codeInsight/ExceptionUtil.java @@ -421,8 +421,12 @@ public class ExceptionUtil { @Override public Pair fun(CandidateInfo info) { PsiElement element = info.getElement(); - return element instanceof PsiMethod && MethodSignatureUtil.areSignaturesEqual(method, (PsiMethod)element) - ? Pair.create((PsiMethod)element, info.getSubstitutor()) : null; + if (element instanceof PsiMethod && + MethodSignatureUtil.areSignaturesEqual(method, (PsiMethod)element) && + !MethodSignatureUtil.isSuperMethod((PsiMethod)element, method)) { + return Pair.create((PsiMethod)element, info.getSubstitutor()); + } + return null; } }); if (candidates.size() > 1) { @@ -456,8 +460,10 @@ public class ExceptionUtil { found = true; break; } else if (classType.isAssignableFrom(psiClassType)) { - replacement.add(psiClassType); - iterator.remove(); + if (isUncheckedException(classType) == isUncheckedException(psiClassType)) { + replacement.add(psiClassType); + iterator.remove(); + } found = true; break; } diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting/IgnoreSuperMethodsInMultipleOverridingCheck.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting/IgnoreSuperMethodsInMultipleOverridingCheck.java new file mode 100644 index 000000000000..943e3732a3d6 --- /dev/null +++ b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting/IgnoreSuperMethodsInMultipleOverridingCheck.java @@ -0,0 +1,21 @@ +class SQLException extends java.lang.Exception{} + +interface ICompileErrorTest { + void foo() throws IllegalStateException, Exception; +} + +abstract class CompileErrorTest implements ICompileErrorTest { + public void foo() throws Exception { + throw new SQLException(); + } +} + +public class CompileErrorTestExtended extends CompileErrorTest { + public void foo() throws Exception { + try { + super.foo(); + } catch (SQLException ignore) { + } + } +} + diff --git a/java/java-tests/testSrc/com/intellij/codeInsight/daemon/LightAdvHighlightingTest.java b/java/java-tests/testSrc/com/intellij/codeInsight/daemon/LightAdvHighlightingTest.java index bb2f2b9fe51e..ba6e5fa4f8a2 100644 --- a/java/java-tests/testSrc/com/intellij/codeInsight/daemon/LightAdvHighlightingTest.java +++ b/java/java-tests/testSrc/com/intellij/codeInsight/daemon/LightAdvHighlightingTest.java @@ -120,6 +120,7 @@ public class LightAdvHighlightingTest extends LightDaemonAnalyzerTestCase { public void testAssignToFinal() { doTest(false, false); } public void testUnhandledExceptionsInSuperclass() { doTest(false, false); } public void testNoUnhandledExceptionsMultipleInheritance() { doTest(false, false); } + public void testIgnoreSuperMethodsInMultipleOverridingCheck() { doTest(false, false); } public void testFalseExceptionsMultipleInheritance() { doTest(true, false); } public void testAssignmentCompatible () { setLanguageLevel(LanguageLevel.JDK_1_5); doTest(false, false); } public void testMustBeBoolean() { doTest(false, false); }