From ce31439c208ad826e15a83b53f45b5c3107c0b5f Mon Sep 17 00:00:00 2001 From: "Egor.Ushakov" Date: Wed, 25 Mar 2015 19:27:51 +0300 Subject: [PATCH] decompiler: removeLast helper to avoid possible errors --- .../java/decompiler/code/InstructionSequence.java | 6 ++++++ .../java/decompiler/modules/code/DeadCodeHelper.java | 2 +- .../decompiler/modules/decompiler/FinallyProcessor.java | 8 ++++---- 3 files changed, 11 insertions(+), 5 deletions(-) diff --git a/src/org/jetbrains/java/decompiler/code/InstructionSequence.java b/src/org/jetbrains/java/decompiler/code/InstructionSequence.java index 705db4e..51951ab 100644 --- a/src/org/jetbrains/java/decompiler/code/InstructionSequence.java +++ b/src/org/jetbrains/java/decompiler/code/InstructionSequence.java @@ -81,6 +81,12 @@ public abstract class InstructionSequence { collinstr.remove(index); } + public void removeLast() { + if (!collinstr.isEmpty()) { + collinstr.remove(collinstr.size() - 1); + } + } + public Instruction getCurrentInstr() { return collinstr.get(pointer); } diff --git a/src/org/jetbrains/java/decompiler/modules/code/DeadCodeHelper.java b/src/org/jetbrains/java/decompiler/modules/code/DeadCodeHelper.java index 233011d..d79367f 100644 --- a/src/org/jetbrains/java/decompiler/modules/code/DeadCodeHelper.java +++ b/src/org/jetbrains/java/decompiler/modules/code/DeadCodeHelper.java @@ -252,7 +252,7 @@ public class DeadCodeHelper { Instruction instr = block.getLastInstruction(); if (instr != null && instr.opcode == CodeConstants.opc_goto) { - block.getSeq().removeInstruction(block.getSeq().length() - 1); + block.getSeq().removeLast(); } } diff --git a/src/org/jetbrains/java/decompiler/modules/decompiler/FinallyProcessor.java b/src/org/jetbrains/java/decompiler/modules/decompiler/FinallyProcessor.java index a49f8f3..3e2be78 100644 --- a/src/org/jetbrains/java/decompiler/modules/decompiler/FinallyProcessor.java +++ b/src/org/jetbrains/java/decompiler/modules/decompiler/FinallyProcessor.java @@ -863,11 +863,11 @@ public class FinallyProcessor { if ((type & 2) > 0) { // last if (finallytype == 0 || finallytype == 2) { - seqPattern.removeInstruction(seqPattern.length() - 1); + seqPattern.removeLast(); } if (finallytype == 2) { - seqPattern.removeInstruction(seqPattern.length() - 1); + seqPattern.removeLast(); } } } @@ -1078,11 +1078,11 @@ public class FinallyProcessor { if ((blocktype & 2) > 0) { // last if (finallytype == 2 || finallytype == 0) { - seq.removeInstruction(seq.length() - 1); + seq.removeLast(); } if (finallytype == 2) { // astore - seq.removeInstruction(seq.length() - 1); + seq.removeLast(); } } }