Author: ggregory
Date: Mon Jun 13 07:15:27 2016
New Revision: 1748099

URL: http://svn.apache.org/viewvc?rev=1748099&view=rev
Log:
Use try-with-resources.

Modified:
    
commons/proper/bcel/trunk/src/main/java/org/apache/bcel/generic/InstructionList.java

Modified: 
commons/proper/bcel/trunk/src/main/java/org/apache/bcel/generic/InstructionList.java
URL: 
http://svn.apache.org/viewvc/commons/proper/bcel/trunk/src/main/java/org/apache/bcel/generic/InstructionList.java?rev=1748099&r1=1748098&r2=1748099&view=diff
==============================================================================
--- 
commons/proper/bcel/trunk/src/main/java/org/apache/bcel/generic/InstructionList.java
 (original)
+++ 
commons/proper/bcel/trunk/src/main/java/org/apache/bcel/generic/InstructionList.java
 Mon Jun 13 07:15:27 2016
@@ -153,14 +153,15 @@ public class InstructionList implements
      *            byte array containing the instructions
      */
     public InstructionList(final byte[] code) {
-        ByteSequence bytes = new ByteSequence(code);
-        InstructionHandle[] ihs = new InstructionHandle[code.length];
-        int[] pos = new int[code.length]; // Can't be more than that
         int count = 0; // Contains actual length
-        /*
-         * Pass 1: Create an object for each byte code and append them to the 
list.
-         */
-        try {
+        int[] pos;
+        InstructionHandle[] ihs;
+        try (ByteSequence bytes = new ByteSequence(code)) {
+            ihs = new InstructionHandle[code.length];
+            pos = new int[code.length]; // Can't be more than that
+            /*
+             * Pass 1: Create an object for each byte code and append them to 
the list.
+             */
             while (bytes.available() > 0) {
                 // Remember byte offset and associate it with the instruction
                 int off = bytes.getIndex();
@@ -952,9 +953,8 @@ public class InstructionList implements
      * @return an array of instructions without target information for branch 
instructions.
      */
     public Instruction[] getInstructions() {
-        ByteSequence bytes = new ByteSequence(getByteCode());
         List<Instruction> instructions = new ArrayList<>();
-        try {
+        try (ByteSequence bytes = new ByteSequence(getByteCode())) {
             while (bytes.available() > 0) {
                 instructions.add(Instruction.readInstruction(bytes));
             }


Reply via email to