harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sjanu...@apache.org
Subject svn commit: r638423 - in /harmony/enhanced/classlib/trunk/modules/pack200/src/main/java/org/apache/harmony/pack200: IcBands.java IcTuple.java Segment.java
Date Tue, 18 Mar 2008 15:55:20 GMT
Author: sjanuary
Date: Tue Mar 18 08:55:14 2008
New Revision: 638423

URL: http://svn.apache.org/viewvc?rev=638423&view=rev
Log:
Apply patch for HARMONY-5607 ([classlib][pack200] Inner class handling is wrong)

Modified:
    harmony/enhanced/classlib/trunk/modules/pack200/src/main/java/org/apache/harmony/pack200/IcBands.java
    harmony/enhanced/classlib/trunk/modules/pack200/src/main/java/org/apache/harmony/pack200/IcTuple.java
    harmony/enhanced/classlib/trunk/modules/pack200/src/main/java/org/apache/harmony/pack200/Segment.java

Modified: harmony/enhanced/classlib/trunk/modules/pack200/src/main/java/org/apache/harmony/pack200/IcBands.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/pack200/src/main/java/org/apache/harmony/pack200/IcBands.java?rev=638423&r1=638422&r2=638423&view=diff
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/pack200/src/main/java/org/apache/harmony/pack200/IcBands.java
(original)
+++ harmony/enhanced/classlib/trunk/modules/pack200/src/main/java/org/apache/harmony/pack200/IcBands.java
Tue Mar 18 08:55:14 2008
@@ -31,9 +31,9 @@
 public class IcBands extends BandSet {
     private IcTuple[] icAll;
 
-    private String[] cpUTF8;
+    private final String[] cpUTF8;
 
-    private String[] cpClass;
+    private final String[] cpClass;
 
     /**
      * @param header
@@ -107,7 +107,14 @@
         int allTuplesSize = allTuples.length;
         for(int index=0; index < allTuplesSize; index++) {
             if(allTuples[index].outerClassString().equals(className)) {
-                relevantTuples.add(allTuples[index]);
+                // Originally I added all classes (anonymous and not anonymous).
+                // That yielded bad results on some classes. Adding just
+                // the non-anonymous classes (which is not what the
+                // spec specifies) seems to fix up a number of cases
+                // where the classes are otherwise mismatched.
+                if(!allTuples[index].isAnonymous()) {
+                    relevantTuples.add(allTuples[index]);
+                }
             }
         }
 

Modified: harmony/enhanced/classlib/trunk/modules/pack200/src/main/java/org/apache/harmony/pack200/IcTuple.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/pack200/src/main/java/org/apache/harmony/pack200/IcTuple.java?rev=638423&r1=638422&r2=638423&view=diff
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/pack200/src/main/java/org/apache/harmony/pack200/IcTuple.java
(original)
+++ harmony/enhanced/classlib/trunk/modules/pack200/src/main/java/org/apache/harmony/pack200/IcTuple.java
Tue Mar 18 08:55:14 2008
@@ -182,4 +182,35 @@
         result.append(')');
         return result.toString();
     }
+
+    public boolean nullSafeEquals(String stringOne, String stringTwo) {
+        if(null==stringOne) {
+            return null==stringTwo;
+        }
+        return stringOne.equals(stringTwo);
+    }
+
+    public boolean equals(Object object) {
+        if(object.getClass() != this.getClass()) {
+            return false;
+        }
+        IcTuple compareTuple = (IcTuple)object;
+
+        if(!nullSafeEquals(this.C, compareTuple.C)) {
+            return false;
+        }
+
+        if(!nullSafeEquals(this.C2, compareTuple.C2)) {
+            return false;
+        }
+
+        if(!nullSafeEquals(this.N, compareTuple.N)) {
+            return false;
+        }
+        return true;
+    }
+
+    public int hashCode() {
+        return 17 + C.hashCode() + C2.hashCode() + N.hashCode();
+    }
 }

Modified: harmony/enhanced/classlib/trunk/modules/pack200/src/main/java/org/apache/harmony/pack200/Segment.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/pack200/src/main/java/org/apache/harmony/pack200/Segment.java?rev=638423&r1=638422&r2=638423&view=diff
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/pack200/src/main/java/org/apache/harmony/pack200/Segment.java
(original)
+++ harmony/enhanced/classlib/trunk/modules/pack200/src/main/java/org/apache/harmony/pack200/Segment.java
Tue Mar 18 08:55:14 2008
@@ -127,29 +127,44 @@
 		int i = fullName.lastIndexOf("/") + 1; // if lastIndexOf==-1, then
 		// -1+1=0, so str.substring(0)
 		// == str
-		AttributeLayout SOURCE_FILE = attrDefinitionBands.getAttributeDefinitionMap()
-				.getAttributeLayout(AttributeLayout.ATTRIBUTE_SOURCE_FILE,
-						AttributeLayout.CONTEXT_CLASS);
-		if (SOURCE_FILE.matches(classBands.getClassFlags()[classNum])) {
-		    int firstDollar = SegmentUtils.indexOfFirstDollar(fullName);
-		    String fileName = null;
-
-		    if(firstDollar > -1 && (i <= firstDollar)) {
-		        fileName = fullName.substring(i, firstDollar) + ".java";
-		    } else {
-		        fileName = fullName.substring(i) + ".java";
-		    }
-			classFile.attributes = new Attribute[] { (Attribute) cp
-					.add(new SourceFileAttribute(cpBands.cpUTF8Value(fileName, ClassConstantPool.DOMAIN_ATTRIBUTEASCIIZ)))
};
-		} else {
-			classFile.attributes = new Attribute[] {};
-		}
-		
+
+		// Get the source file attribute
+        ArrayList classAttributes = classBands.getClassAttributes()[classNum];
+        SourceFileAttribute sourceFileAttribute = null;
+        for(int index=0; index < classAttributes.size(); index++) {
+            if(((Attribute)classAttributes.get(index)).isSourceFileAttribute()) {
+                sourceFileAttribute = ((SourceFileAttribute)classAttributes.get(index));
+            }
+        }
+
+        if(sourceFileAttribute == null) {
+            // If we don't have a source file attribute yet, we need
+            // to infer it from the class.
+            AttributeLayout SOURCE_FILE = attrDefinitionBands.getAttributeDefinitionMap()
+    				.getAttributeLayout(AttributeLayout.ATTRIBUTE_SOURCE_FILE,
+    						AttributeLayout.CONTEXT_CLASS);
+    		if (SOURCE_FILE.matches(classBands.getClassFlags()[classNum])) {
+    		    int firstDollar = SegmentUtils.indexOfFirstDollar(fullName);
+    		    String fileName = null;
+
+    		    if(firstDollar > -1 && (i <= firstDollar)) {
+    		        fileName = fullName.substring(i, firstDollar) + ".java";
+    		    } else {
+    		        fileName = fullName.substring(i) + ".java";
+    		    }
+    		    sourceFileAttribute = new SourceFileAttribute(cpBands.cpUTF8Value(fileName, ClassConstantPool.DOMAIN_ATTRIBUTEASCIIZ));
+    			classFile.attributes = new Attribute[] { (Attribute) cp
+    					.add(sourceFileAttribute) };
+    		} else {
+                classFile.attributes = new Attribute[] {};
+            }
+        } else {
+            classFile.attributes = new Attribute[] { (Attribute) cp.add(sourceFileAttribute)};
+        }
+
 		// If we see any class attributes, add them to the class's attributes that will
 		// be written out. Keep SourceFileAttributes out since we just
-		// did them above. (One of the computations for SourceFileAttribute
-		// may be redundant.)
-	    ArrayList classAttributes = classBands.getClassAttributes()[classNum];
+		// did them above.
 	    ArrayList classAttributesWithoutSourceFileAttribute = new ArrayList();
 	    for(int index=0; index < classAttributes.size(); index++) {
 	        Attribute attrib = (Attribute)classAttributes.get(index);
@@ -159,7 +174,7 @@
 	    }
         Attribute[] originalAttributes = classFile.attributes;
         classFile.attributes = new Attribute[originalAttributes.length + classAttributesWithoutSourceFileAttribute.size()];
-        System.arraycopy(originalAttributes, 0, classFile.attributes, 0, originalAttributes.length);
       
+        System.arraycopy(originalAttributes, 0, classFile.attributes, 0, originalAttributes.length);
 	    for(int index=0; index < classAttributesWithoutSourceFileAttribute.size(); index++)
{
 	        Attribute attrib = ((Attribute)classAttributesWithoutSourceFileAttribute.get(index));
 	        cp.add(attrib);
@@ -200,11 +215,23 @@
 
 		// add inner class attribute (if required)
 		boolean addInnerClassesAttr = false;
+		// TODO: remove the debug info below
+//        String debugClass = getClassBands().getClassThis()[classNum];
+//        SegmentUtils.debug("buildClassFile: class is " + debugClass);
+//        if("com/ibm/collaboration/realtime/application/RTCMainPlugin".equals(foo)) {
+//            SegmentUtils.debug("self halt");
+//        }
 		IcTuple[] ic_local = getClassBands().getIcLocal()[classNum];
 		boolean ic_local_sent = false;
 		if(ic_local != null) {
 		    ic_local_sent = true;
 		}
+		// TODO: remove the debug code below
+//		if(ic_local_sent) {
+//		    for(int xx = 0; xx < ic_local.length; xx++) {
+//		        SegmentUtils.debug("ic_local[" + xx + "]=" + ic_local[xx]);
+//		    }
+//		}
 		InnerClassesAttribute innerClassesAttribute = new InnerClassesAttribute("InnerClasses");
 		IcTuple[] ic_relevant = getIcBands().getRelevantIcTuples(fullName, cp);
 		IcTuple[] ic_stored = computeIcStored(ic_local, ic_relevant);



Mime
View raw message