harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ge...@apache.org
Subject svn commit: r451082 - /incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/io/ObjectStreamClass.java
Date Fri, 29 Sep 2006 01:58:00 GMT
Author: geirm
Date: Thu Sep 28 18:58:00 2006
New Revision: 451082

URL: http://svn.apache.org/viewvc?view=rev&rev=451082
Log:
HARMONY-1123

computeSerialVersionUID() returned the wrong value compared to
the scribbled footnote jokingly referred to as the spec as
implemented by the RI

The result was a serialized instance of a class that didn't have
a set serialVersionUID field wasn't de-serializable by Harmony.

For simple tests, we now return the same ID as the RI.

All classlib tests passed.

We need more tests, ones that specifically test this with complicated
classes that are precompiled with the RI's serialVersionUID known.



Modified:
    incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/io/ObjectStreamClass.java

Modified: incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/io/ObjectStreamClass.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/io/ObjectStreamClass.java?view=diff&rev=451082&r1=451081&r2=451082
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/io/ObjectStreamClass.java
(original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/io/ObjectStreamClass.java
Thu Sep 28 18:58:00 2006
@@ -58,7 +58,9 @@
 	private static final String UID_FIELD_NAME = "serialVersionUID"; //$NON-NLS-1$
 
 	private static final int CLASS_MODIFIERS_MASK;
-
+    private static final int FIELD_MODIFIERS_MASK;
+    private static final int METHOD_MODIFIERS_MASK;
+    
 	private static final Class[] READ_PARAM_TYPES;
 
 	private static final Class[] WRITE_PARAM_TYPES;
@@ -76,6 +78,14 @@
 
 		CLASS_MODIFIERS_MASK = Modifier.PUBLIC | Modifier.FINAL
 				| Modifier.INTERFACE | Modifier.ABSTRACT;
+        FIELD_MODIFIERS_MASK= Modifier.PUBLIC | Modifier.PRIVATE
+                | Modifier.PROTECTED | Modifier.STATIC | Modifier.FINAL
+                | Modifier.VOLATILE | Modifier.TRANSIENT;
+        METHOD_MODIFIERS_MASK= Modifier.PUBLIC | Modifier.PRIVATE
+                | Modifier.PROTECTED | Modifier.STATIC | Modifier.FINAL
+                | Modifier.SYNCHRONIZED | Modifier.NATIVE
+                | Modifier.ABSTRACT | Modifier.STRICT;
+        
 		READ_PARAM_TYPES = new Class[1];
 		WRITE_PARAM_TYPES = new Class[1];
 		READ_PARAM_TYPES[0] = ObjectInputStream.class;
@@ -410,7 +420,8 @@
 			// Dump them
 			for (int i = 0; i < fields.length; i++) {
 				Field field = fields[i];
-				int modifiers = field.getModifiers();
+				int modifiers = field.getModifiers() & FIELD_MODIFIERS_MASK;
+                
 				boolean skip = Modifier.isPrivate(modifiers)
 						&& (Modifier.isTransient(modifiers) || Modifier
 								.isStatic(modifiers));
@@ -437,7 +448,7 @@
 				output.writeUTF(CLINIT_SIGNATURE);
 			}
 
-			// ------------------ Constructor information
+            // ------------------ Constructor information
 			Constructor<?>[] constructors = cl.getDeclaredConstructors();
 			if (constructors.length > 1) {
                 /*
@@ -458,7 +469,7 @@
 			// Dump them
 			for (int i = 0; i < constructors.length; i++) {
 				Constructor<?> constructor = constructors[i];
-				int modifiers = constructor.getModifiers();
+				int modifiers = constructor.getModifiers() & METHOD_MODIFIERS_MASK;
 				boolean isPrivate = Modifier.isPrivate(modifiers);
 				if (!isPrivate) {
                     /*
@@ -471,7 +482,7 @@
                     output.writeUTF("<init>"); //$NON-NLS-1$
                     output.writeInt(modifiers);
                     output.writeUTF(descriptorForSignature(
-                            getConstructorSignature(constructor)));
+                            getConstructorSignature(constructor)).replace('/','.'));
                 }
 			}
 
@@ -496,15 +507,15 @@
 			// Dump them
 			for (int i = 0; i < methods.length; i++) {
 				Method method = methods[i];
-				int modifiers = method.getModifiers();
+				int modifiers = method.getModifiers() & METHOD_MODIFIERS_MASK;
 				boolean isPrivate = Modifier.isPrivate(modifiers);
 				if (!isPrivate) {
 					// write name, modifier & "descriptor" of all but private
 					// ones
 					output.writeUTF(method.getName());
 					output.writeInt(modifiers);
-					output.writeUTF(descriptorForSignature(
-                            getMethodSignature(method)));
+                    output.writeUTF(descriptorForSignature(
+                            getMethodSignature(method)).replace('/', '.'));
 				}
 			}
 		} catch (IOException e) {
@@ -513,6 +524,7 @@
 
 		// now compute the UID based on the SHA
 		byte[] hash = digest.digest(sha.toByteArray());
+                
 		return littleEndianLongAt(hash, 0);
 
 	}



Mime
View raw message