[java-inspections] Fix handling unreachable statements after try (IDEA-226599)

GitOrigin-RevId: 206f9f82c377ed1301986585f20d4b0fc7c99a30
This commit is contained in:
Tagir Valeev
2022-06-06 15:24:44 +00:00
committed by intellij-monorepo-bot
parent b7c6103f12
commit 283d54c49b
3 changed files with 25 additions and 2 deletions
@@ -90,8 +90,9 @@ public class DeleteCatchFix implements IntentionActionWithFixAllOption {
boolean mayCompleteNormally = ControlFlowUtils.codeBlockMayCompleteNormally(tryBlock);
if (!mayCompleteNormally) {
PsiElement nextElement = PsiTreeUtil.skipWhitespacesAndCommentsForward(tryStatement.getNextSibling());
PsiElement lastElement = PsiTreeUtil.skipWhitespacesAndCommentsBackward(((PsiCodeBlock)tryParent).getRBrace());
if (nextElement != null && lastElement != null) {
PsiJavaToken rBrace = ((PsiCodeBlock)tryParent).getRBrace();
PsiElement lastElement = PsiTreeUtil.skipWhitespacesAndCommentsBackward(rBrace);
if (nextElement != null && lastElement != null && nextElement != rBrace) {
tryParent.deleteChildRange(nextElement, lastElement);
}
}
@@ -0,0 +1,9 @@
// "Replace with 'cs'" "true"
import java.nio.charset.*;
import java.io.UnsupportedEncodingException;
class X {
byte[] convert(String str, Charset cs) {
return str.getBytes(cs);
}
}
@@ -0,0 +1,13 @@
// "Replace with 'cs'" "true"
import java.nio.charset.*;
import java.io.UnsupportedEncodingException;
class X {
byte[] convert(String str, Charset cs) {
try {
return str.getBytes(<caret>cs.name());
} catch (UnsupportedEncodingException e) {
throw new RuntimeException(e);
}
}
}