harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sjanu...@apache.org
Subject svn commit: r692141 - in /harmony/enhanced/classlib/trunk/modules/pack200/src/main/java/org/apache/harmony/unpack200: ClassBands.java NewAttributeBands.java bytecode/NewAttribute.java
Date Thu, 04 Sep 2008 16:30:08 GMT
Author: sjanuary
Date: Thu Sep  4 09:30:07 2008
New Revision: 692141

URL: http://svn.apache.org/viewvc?rev=692141&view=rev
Log:
Fix for HARMONY-5968 ([pack200][classlib] NumberFormatException in NewAttributeBands.readNumber())

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

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=692141&r1=692140&r2=692141&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
Thu Sep  4 09:30:07 2008
@@ -394,9 +394,6 @@
                         otherAttributes[k].remove(0);
                     }
                 }
-                if (deprecatedLayout.matches(flag)) {
-                    methodAttributes[i][j].add(new DeprecatedAttribute());
-                }
                 if (methodExceptionsLayout.matches(flag)) {
                     int n = numExceptions[methodExceptionsIndex];
                     int[] exceptions = methodExceptionsRS[methodExceptionsIndex];
@@ -409,6 +406,9 @@
                             exceptionClasses));
                     methodExceptionsIndex++;
                 }
+                if (deprecatedLayout.matches(flag)) {
+                    methodAttributes[i][j].add(new DeprecatedAttribute());
+                }
                 if (methodSignatureLayout.matches(flag)) {
                     // We've got a signature attribute
                     long result = methodSignatureRS[methodSignatureIndex];

Modified: harmony/enhanced/classlib/trunk/modules/pack200/src/main/java/org/apache/harmony/unpack200/NewAttributeBands.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/pack200/src/main/java/org/apache/harmony/unpack200/NewAttributeBands.java?rev=692141&r1=692140&r2=692141&view=diff
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/pack200/src/main/java/org/apache/harmony/unpack200/NewAttributeBands.java
(original)
+++ harmony/enhanced/classlib/trunk/modules/pack200/src/main/java/org/apache/harmony/unpack200/NewAttributeBands.java
Thu Sep  4 09:30:07 2008
@@ -20,6 +20,7 @@
 import java.io.InputStream;
 import java.io.StringReader;
 import java.util.ArrayList;
+import java.util.Iterator;
 import java.util.List;
 
 import org.apache.harmony.pack200.BHSDCodec;
@@ -82,7 +83,7 @@
 
         List attributes = new ArrayList(occurrenceCount);
         for (int i = 0; i < occurrenceCount; i++) {
-            attributes.add(getOneAttribute(i, attributeLayoutElements));
+        	attributes.add(getOneAttribute(i, attributeLayoutElements));
         }
         return attributes;
     }
@@ -137,49 +138,67 @@
                     .get(i);
             if (element instanceof Callable) {
                 Callable callable = (Callable) element;
+                if(i == 0) {
+                	callable.setFirstCallable(true);
+                }
                 List body = callable.body; // Look for calls in the body
                 for(int iIndex = 0; iIndex < body.size(); iIndex++) {
-                    LayoutElement layoutElement = (LayoutElement) body.get(iIndex);
-                    if (layoutElement instanceof Call) {
-                        // Set the callable for each call
-                        Call call = (Call) layoutElement;
-                        int index = call.callableIndex;
-                        if (index == 0) { // Calls the parent callable
-                            backwardsCalls++;
-                            call.setCallable(callable);
-                        } else if (index > 0) { // Forwards call
-                            for (int k = i; k < attributeLayoutElements.size(); k++) {
-                                AttributeLayoutElement el = (AttributeLayoutElement) attributeLayoutElements
-                                        .get(k);
-                                if (el instanceof Callable) {
-                                    index--;
-                                    if (index == 0) {
-                                        call.setCallable((Callable) el);
-                                        break;
-                                    }
-                                }
-                            }
-                        } else { // Backwards call
-                            backwardsCalls++;
-                            for (int k = i; k >= 0; k--) {
-                                AttributeLayoutElement el = (AttributeLayoutElement) attributeLayoutElements
-                                        .get(k);
-                                if (el instanceof Callable) {
-                                    index++;
-                                    if (index == 0) {
-                                        call.setCallable((Callable) el);
-                                        break;
-                                    }
-                                }
-                            }
-                        }
-                    }
+                    LayoutElement layoutElement = (LayoutElement) body
+							.get(iIndex);
+					// Set the callable for each call
+					backwardsCalls += resolveCallsForElement(i, callable,
+							layoutElement);
                 }
             }
         }
         backwardsCallCount = backwardsCalls;
     }
 
+	private int resolveCallsForElement(int i,
+			Callable currentCallable, LayoutElement layoutElement) {
+		int backwardsCalls = 0;
+		if (layoutElement instanceof Call) {
+            Call call = (Call) layoutElement;
+			int index = call.callableIndex;
+			if (index == 0) { // Calls the parent callable
+			    backwardsCalls++;
+			    call.setCallable(currentCallable);
+			} else if (index > 0) { // Forwards call
+			    for (int k = i + 1; k < attributeLayoutElements.size(); k++) {
+			        AttributeLayoutElement el = (AttributeLayoutElement) attributeLayoutElements
+			                .get(k);
+			        if (el instanceof Callable) {
+			            index--;
+			            if (index == 0) {
+			                call.setCallable((Callable) el);
+			                break;
+			            }
+			        }
+			    }
+			} else { // Backwards call
+			    backwardsCalls++;
+			    for (int k = i; k >= 0; k--) {
+			        AttributeLayoutElement el = (AttributeLayoutElement) attributeLayoutElements
+			                .get(k);
+			        if (el instanceof Callable) {
+			            index++;
+			            if (index == 0) {
+			                call.setCallable((Callable) el);
+			                break;
+			            }
+			        }
+			    }
+			}
+		} else if (layoutElement instanceof Replication) {
+			List children = ((Replication)layoutElement).layoutElements;
+			for (Iterator iterator = children.iterator(); iterator.hasNext();) {
+				LayoutElement object = (LayoutElement) iterator.next();
+				backwardsCalls += resolveCallsForElement(i, currentCallable, object);
+			}
+		}
+		return backwardsCalls;
+	}
+
     private AttributeLayoutElement readNextAttributeElement(StringReader stream)
             throws IOException {
         int nextChar = stream.read();
@@ -196,7 +215,7 @@
 
     private LayoutElement readNextLayoutElement(StringReader stream)
             throws IOException {
-        int nextChar = stream.read();
+        char nextChar = (char)stream.read();
         if (nextChar == -1) {
             return null;
         }
@@ -206,10 +225,10 @@
         case 'H':
         case 'I':
         case 'V':
-            return new Integral(new String(new char[] { (char) nextChar }));
+            return new Integral(new String(new char[] { nextChar }));
         case 'S':
         case 'F':
-            return new Integral(new String(new char[] { (char) nextChar,
+            return new Integral(new String(new char[] { nextChar,
                     (char) stream.read() }));
         case 'P':
             stream.mark(1);
@@ -247,7 +266,7 @@
                 unionCases.add(c);
             }
             stream.read(); // '('
-            stream.read(); // '('
+            stream.read(); // ')'
             stream.read(); // '['
             List body = null;
             stream.mark(1);
@@ -260,7 +279,7 @@
 
             // Call
         case '(':
-            int number = readNumber(stream);
+            int number = readNumber(stream).intValue();
             stream.read(); // ')'
             return new Call(number);
             // Reference
@@ -291,12 +310,19 @@
         if (next == ')') {
             stream.reset();
             return null;
+        } else {
+            stream.reset();
+            stream.read(); // '('
         }
         List tags = new ArrayList();
-        while (next != ')') {
-            tags.add(new Integer(readNumber(stream)));
-            next = (char) stream.read();
-        }
+        Integer nextTag;
+        do {
+        	nextTag = readNumber(stream);
+            if(nextTag != null) {
+            	tags.add(nextTag);
+                stream.read(); // ',' or ')'
+            }
+        } while (nextTag != null);
         stream.read(); // '['
         stream.mark(1);
         next = (char) stream.read();
@@ -619,7 +645,7 @@
 
         public Reference(String tag) {
             this.tag = tag;
-            length = getLength(tag.charAt(tag.length()));
+            length = getLength(tag.charAt(tag.length() - 1));
         }
 
         public void readBands(InputStream in, int count) throws IOException,
@@ -700,6 +726,8 @@
 
         private boolean isBackwardsCallable;
 
+		private boolean isFirstCallable;
+
         public Callable(List body) throws IOException {
             this.body = body;
         }
@@ -732,7 +760,11 @@
 
         public void readBands(InputStream in, int count) throws IOException,
                 Pack200Exception {
-            count += this.count;
+        	if(isFirstCallable) {
+        		count += this.count;
+        	} else {
+        		count = this.count;
+        	}
             for(int i = 0; i < body.size(); i++) {
                 LayoutElement element = (LayoutElement) body.get(i);
                 element.readBands(in, count);
@@ -740,12 +772,14 @@
         }
 
         public void addToAttribute(int n, NewAttribute attribute) {
-            // Ignore n because bands also contain element parts from calls
-            for(int i = 0; i < body.size(); i++) {
-                LayoutElement element = (LayoutElement) body.get(i);
-                element.addToAttribute(index, attribute);
-            }
-            index++;
+        	if(isFirstCallable) {
+	            // Ignore n because bands also contain element parts from calls
+	            for(int i = 0; i < body.size(); i++) {
+	                LayoutElement element = (LayoutElement) body.get(i);
+	                element.addToAttribute(index, attribute);
+	            }
+	            index++;
+        	}
         }
 
         public boolean isBackwardsCallable() {
@@ -758,6 +792,10 @@
         public void setBackwardsCallable() {
             this.isBackwardsCallable = true;
         }
+
+		public void setFirstCallable(boolean isFirstCallable) {
+			this.isFirstCallable = isFirstCallable;
+		}
     }
 
     /**
@@ -884,7 +922,7 @@
      * @return
      * @throws IOException
      */
-    private int readNumber(StringReader stream) throws IOException {
+    private Integer readNumber(StringReader stream) throws IOException {
         stream.mark(1);
         char first = (char) stream.read();
         boolean negative = first == '-';
@@ -898,12 +936,15 @@
             length++;
         }
         stream.reset();
+        if(length == 0) {
+        	return null;
+        }
         char[] digits = new char[length];
         int read = stream.read(digits);
         if (read != digits.length) {
             throw new IOException("Error reading from the input stream");
         }
-        return Integer.parseInt((negative ? "-" : "") + new String(digits));
+        return new Integer(Integer.parseInt((negative ? "-" : "") + new String(digits)));
     }
 
     /**

Modified: harmony/enhanced/classlib/trunk/modules/pack200/src/main/java/org/apache/harmony/unpack200/bytecode/NewAttribute.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/pack200/src/main/java/org/apache/harmony/unpack200/bytecode/NewAttribute.java?rev=692141&r1=692140&r2=692141&view=diff
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/pack200/src/main/java/org/apache/harmony/unpack200/bytecode/NewAttribute.java
(original)
+++ harmony/enhanced/classlib/trunk/modules/pack200/src/main/java/org/apache/harmony/unpack200/bytecode/NewAttribute.java
Thu Sep  4 09:30:07 2008
@@ -159,6 +159,27 @@
         this.pool = pool;
     }
 
+    protected ClassFileEntry[] getNestedClassFileEntries() {
+    	int total = 1;
+    	for(int iter = 0; iter < body.size(); iter++) {
+            Object element = body.get(iter);
+            if (element instanceof ClassFileEntry) {
+                total++;
+            }
+        }
+    	ClassFileEntry[] nested = new ClassFileEntry[total];
+    	nested[0] = getAttributeName();
+    	int i = 1;
+    	for(int iter = 0; iter < body.size(); iter++) {
+            Object element = body.get(iter);
+            if (element instanceof ClassFileEntry) {
+            	nested[i] = (ClassFileEntry) element;
+                i++;
+            }
+        }
+    	return nested;
+    }
+
     private static class BCOffset extends BCValue {
 
         private final int offset;



Mime
View raw message