harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sjanu...@apache.org
Subject svn commit: r690951 - in /harmony/enhanced/classlib/trunk/modules/pack200/src/main/java/org/apache/harmony/unpack200: BcBands.java ClassBands.java
Date Mon, 01 Sep 2008 12:08:09 GMT
Author: sjanuary
Date: Mon Sep  1 05:08:09 2008
New Revision: 690951

URL: http://svn.apache.org/viewvc?rev=690951&view=rev
Log:
Tentative fix for HARMONY-5960 ([pack200][classlib] IndexOutOfBounds exception in BcBands.unpack())

Modified:
    harmony/enhanced/classlib/trunk/modules/pack200/src/main/java/org/apache/harmony/unpack200/BcBands.java
    harmony/enhanced/classlib/trunk/modules/pack200/src/main/java/org/apache/harmony/unpack200/ClassBands.java

Modified: harmony/enhanced/classlib/trunk/modules/pack200/src/main/java/org/apache/harmony/unpack200/BcBands.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/pack200/src/main/java/org/apache/harmony/unpack200/BcBands.java?rev=690951&r1=690950&r2=690951&view=diff
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/pack200/src/main/java/org/apache/harmony/unpack200/BcBands.java
(original)
+++ harmony/enhanced/classlib/trunk/modules/pack200/src/main/java/org/apache/harmony/unpack200/BcBands.java
Mon Sep  1 05:08:09 2008
@@ -20,6 +20,7 @@
 import java.io.IOException;
 import java.io.InputStream;
 import java.util.ArrayList;
+import java.util.Collections;
 import java.util.List;
 
 import org.apache.harmony.pack200.Codec;
@@ -396,6 +397,7 @@
         int i = 0;
         ArrayList orderedCodeAttributes = segment.getClassBands()
                 .getOrderedCodeAttributes();
+        int codeAttributeIndex = 0;
 
         // Exception table fields
         int[] handlerCount = segment.getClassBands().getCodeHandlerCount();
@@ -407,6 +409,9 @@
         int[][] handlerClassTypes = segment.getClassBands()
                 .getCodeHandlerClassRCN();
 
+        boolean allCodeHasFlags = segment.getSegmentHeader().getOptions().hasAllCodeFlags();
+        boolean[] codeHasFlags = segment.getClassBands().getCodeHasAttributes();
+
         for (int c = 0; c < classCount; c++) {
             int numberOfMethods = methodFlags[c].length;
             for (int m = 0; m < numberOfMethods; m++) {
@@ -459,18 +464,26 @@
                     }
                     methodAttributesList.add(indexForCodeAttr, codeAttr);
                     codeAttr.renumber(codeAttr.byteCodeOffsets);
-                    if(orderedCodeAttributes.size() > 0) {
-                        ArrayList currentAttributes = (ArrayList) orderedCodeAttributes
-                                .get(i);
-                        for (int index = 0; index < currentAttributes.size(); index++)
{
-                            Attribute currentAttribute = (Attribute) currentAttributes
-                                    .get(index);
-                            codeAttr.addAttribute(currentAttribute);
-                            // Fix up the line numbers if needed
-                            if (currentAttribute.hasBCIRenumbering()) {
-                                ((BCIRenumberedAttribute) currentAttribute)
-                                        .renumber(codeAttr.byteCodeOffsets);
-                            }
+                    List currentAttributes;
+                    if (allCodeHasFlags) {
+                        currentAttributes = (List) orderedCodeAttributes.get(i);
+                    } else {
+                        if (codeHasFlags[i]) {
+                            currentAttributes = (List) orderedCodeAttributes
+                                    .get(codeAttributeIndex);
+                            codeAttributeIndex++;
+                        } else {
+                            currentAttributes = Collections.EMPTY_LIST;
+                        }
+                    }
+                    for (int index = 0; index < currentAttributes.size(); index++) {
+                        Attribute currentAttribute = (Attribute) currentAttributes
+                                .get(index);
+                        codeAttr.addAttribute(currentAttribute);
+                        // Fix up the line numbers if needed
+                        if (currentAttribute.hasBCIRenumbering()) {
+                            ((BCIRenumberedAttribute) currentAttribute)
+                                    .renumber(codeAttr.byteCodeOffsets);
                         }
                     }
                     i++;

Modified: harmony/enhanced/classlib/trunk/modules/pack200/src/main/java/org/apache/harmony/unpack200/ClassBands.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/pack200/src/main/java/org/apache/harmony/unpack200/ClassBands.java?rev=690951&r1=690950&r2=690951&view=diff
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/pack200/src/main/java/org/apache/harmony/unpack200/ClassBands.java
(original)
+++ harmony/enhanced/classlib/trunk/modules/pack200/src/main/java/org/apache/harmony/unpack200/ClassBands.java
Mon Sep  1 05:08:09 2008
@@ -68,7 +68,7 @@
 
     private IcTuple[][] icLocal;
 
-    private ArrayList[] codeAttributes;
+    private List[] codeAttributes;
 
     private int[] codeHandlerCount;
 
@@ -114,6 +114,8 @@
 
     private int[][] codeHandlerClassRCN;
 
+    private boolean [] codeHasAttributes;
+
     /**
      * @param segment
      */
@@ -718,10 +720,19 @@
         int codeCount = SegmentUtils.countMatches(methodFlags, layout);
         int[] codeHeaders = decodeBandInt("code_headers", in, Codec.BYTE1,
                 codeCount);
+
+        boolean allCodeHasFlags = segment.getSegmentHeader().getOptions().hasAllCodeFlags();
+        if(!allCodeHasFlags) {
+            codeHasAttributes = new boolean[codeCount];
+        }
         int codeSpecialHeader = 0;
         for (int i = 0; i < codeCount; i++) {
-            if (codeHeaders[i] == 0)
+            if (codeHeaders[i] == 0) {
                 codeSpecialHeader++;
+                if(!allCodeHasFlags) {
+                    codeHasAttributes[i] = true;
+                }
+            }
         }
         int[] codeMaxStackSpecials = decodeBandInt("code_max_stack", in,
                 Codec.UNSIGNED5, codeSpecialHeader);
@@ -768,10 +779,9 @@
         codeHandlerClassRCN = decodeBandInt(
                 "code_handler_class_RCN", in, Codec.UNSIGNED5, codeHandlerCount);
 
-        int codeFlagsCount = segment.getSegmentHeader().getOptions()
-                .hasAllCodeFlags() ? codeCount : codeSpecialHeader;
+        int codeFlagsCount = allCodeHasFlags ? codeCount : codeSpecialHeader;
 
-        codeAttributes = new ArrayList[codeFlagsCount];
+        codeAttributes = new List[codeFlagsCount];
         for (int i = 0; i < codeAttributes.length; i++) {
             codeAttributes[i] = new ArrayList();
         }
@@ -1389,4 +1399,8 @@
         return icLocal;
     }
 
+    public boolean[] getCodeHasAttributes() {
+        return codeHasAttributes;
+    }
+
 }



Mime
View raw message