From 46c33c46e3dacfc6f33d23c3180b40d5b458a339 Mon Sep 17 00:00:00 2001 From: Mikhail Pyltsin Date: Mon, 19 Aug 2024 23:55:03 +0200 Subject: [PATCH] [java-intention] IDEA-357879 "Replace `catch` sections with `throw`" intention doesn't check ancestors - fix test's flakiness GitOrigin-RevId: ce2d52a107441215c5c8f953916e2203196fbc25 --- .../siyeh/ipp/exceptions/ConvertCatchToThrowsIntention.java | 2 +- .../com/siyeh/ipp/exceptions/ConvertCatchToThrowsTest.java | 5 +++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/java/java-impl/src/com/siyeh/ipp/exceptions/ConvertCatchToThrowsIntention.java b/java/java-impl/src/com/siyeh/ipp/exceptions/ConvertCatchToThrowsIntention.java index 684e293bb1ee..dd1b532a9565 100644 --- a/java/java-impl/src/com/siyeh/ipp/exceptions/ConvertCatchToThrowsIntention.java +++ b/java/java-impl/src/com/siyeh/ipp/exceptions/ConvertCatchToThrowsIntention.java @@ -69,7 +69,7 @@ public final class ConvertCatchToThrowsIntention extends PsiBasedModCommandActio PsiFile containingFile = catchSection.getContainingFile(); PsiFile copyCatchSectionContainingFile = copyCatchSection.getContainingFile(); for (PsiMethod superMethod : superMethods) { - if (!superMethod.isWritable() || !superMethod.isPhysical()) continue; + if (!superMethod.isPhysical() || superMethod instanceof PsiCompiledElement) continue; if (superMethod.getContainingFile() == containingFile) { superMethodsToModify.add( PsiTreeUtil.findSameElementInCopy(superMethod, copyCatchSectionContainingFile)); diff --git a/java/java-tests/testSrc/com/siyeh/ipp/exceptions/ConvertCatchToThrowsTest.java b/java/java-tests/testSrc/com/siyeh/ipp/exceptions/ConvertCatchToThrowsTest.java index e1f8aa18ab91..bea57355a6eb 100644 --- a/java/java-tests/testSrc/com/siyeh/ipp/exceptions/ConvertCatchToThrowsTest.java +++ b/java/java-tests/testSrc/com/siyeh/ipp/exceptions/ConvertCatchToThrowsTest.java @@ -3,6 +3,8 @@ */ package com.siyeh.ipp.exceptions; +import com.intellij.ui.ChooserInterceptor; +import com.intellij.ui.UiInterceptors; import com.siyeh.IntentionPowerPackBundle; import com.siyeh.ipp.IPPTestCase; @@ -23,6 +25,9 @@ public class ConvertCatchToThrowsTest extends IPPTestCase { public void testInLoopSingleLine() { doTest(); } public void testInLoopSingleLineDeclaration() { doTest(); } public void testWithSuperMethods() { + UiInterceptors.register( + new ChooserInterceptor(null, + IntentionPowerPackBundle.message("convert.catch.to.throws.super.and.current.methods"))); doTest(); }