harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From telli...@apache.org
Subject svn commit: r571898 - in /harmony/enhanced/classlib/trunk/modules/luni/src: main/java/java/io/ObjectStreamClass.java test/api/common/tests/api/java/io/ObjectStreamClassTest.java
Date Sat, 01 Sep 2007 23:25:29 GMT
Author: tellison
Date: Sat Sep  1 16:25:28 2007
New Revision: 571898

URL: http://svn.apache.org/viewvc?rev=571898&view=rev
Log:
Proxy and Enum classes always have serialization stream ID of zero.

Modified:
    harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/io/ObjectStreamClass.java
    harmony/enhanced/classlib/trunk/modules/luni/src/test/api/common/tests/api/java/io/ObjectStreamClassTest.java

Modified: harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/io/ObjectStreamClass.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/io/ObjectStreamClass.java?rev=571898&r1=571897&r2=571898&view=diff
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/io/ObjectStreamClass.java
(original)
+++ harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/io/ObjectStreamClass.java
Sat Sep  1 16:25:28 2007
@@ -22,6 +22,7 @@
 import java.lang.reflect.Field;
 import java.lang.reflect.Method;
 import java.lang.reflect.Modifier;
+import java.lang.reflect.Proxy;
 import java.security.AccessController;
 import java.security.MessageDigest;
 import java.security.NoSuchAlgorithmException;
@@ -203,6 +204,10 @@
 
         ObjectStreamClass result = new ObjectStreamClass();
 
+        boolean isProxy = Proxy.isProxyClass(cl);
+        boolean isEnum = Enum.class.isAssignableFrom(cl);
+        boolean isArray = cl.isArray();
+
         // Now we fill in the values
         result.setName(cl.getName());
         result.setClass(cl);
@@ -214,22 +219,24 @@
         Field[] declaredFields = null;
         if (computeSUID) {
             // Lazy computation, to save speed & space
-            declaredFields = cl.getDeclaredFields();
-            result.setSerialVersionUID((cl.isEnum() || (cl == Enum.class)) ? 0
-                    : computeSerialVersionUID(cl, declaredFields));
+            if (isEnum || isProxy) {
+                result.setSerialVersionUID(0L);
+            } else {
+                declaredFields = cl.getDeclaredFields();
+                result.setSerialVersionUID(computeSerialVersionUID(cl, declaredFields));
+            }
         }
 
         boolean serializable = isSerializable(cl);
         // Serializables need field descriptors
-        if (serializable && !cl.isArray()) {
+        if (serializable && !isArray) {
             if (declaredFields == null) {
-
                 declaredFields = cl.getDeclaredFields();
             }
             result.buildFieldDescriptors(declaredFields);
         } else {
             // Externalizables or arrays do not need FieldDesc info
-            result.setFields(new ObjectStreamField[0]);
+            result.setFields(NO_FIELDS);
         }
 
         // Copy all fields to loadFields - they should be read by default in
@@ -669,7 +676,7 @@
                 buildFieldDescriptors(forCl.getDeclaredFields());
             } else {
                 // Externalizables or arrays do not need FieldDesc info
-                setFields(new ObjectStreamField[0]);
+                setFields(NO_FIELDS);
             }
         }
         return fields;

Modified: harmony/enhanced/classlib/trunk/modules/luni/src/test/api/common/tests/api/java/io/ObjectStreamClassTest.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/luni/src/test/api/common/tests/api/java/io/ObjectStreamClassTest.java?rev=571898&r1=571897&r2=571898&view=diff
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/luni/src/test/api/common/tests/api/java/io/ObjectStreamClassTest.java
(original)
+++ harmony/enhanced/classlib/trunk/modules/luni/src/test/api/common/tests/api/java/io/ObjectStreamClassTest.java
Sat Sep  1 16:25:28 2007
@@ -20,6 +20,7 @@
 import java.io.ObjectStreamClass;
 import java.io.ObjectStreamField;
 import java.io.Serializable;
+import java.lang.reflect.Proxy;
 
 public class ObjectStreamClassTest extends junit.framework.TestCase {
 
@@ -128,17 +129,26 @@
         assertEquals(0, osc.getFields().length);
     }
     
-	/**
-	 * Sets up the fixture, for example, open a network connection. This method
-	 * is called before a test is executed.
-	 */
-	protected void setUp() {
-	}
-
-	/**
-	 * Tears down the fixture, for example, close a network connection. This
-	 * method is called after a test is executed.
-	 */
-	protected void tearDown() {
-	}
+    public void test_specialTypes() {
+        Class<?> proxyClass = Proxy.getProxyClass(this.getClass()
+                .getClassLoader(), new Class[] { Runnable.class });
+
+        ObjectStreamClass proxyStreamClass = ObjectStreamClass
+                .lookup(proxyClass);
+
+        assertEquals("Proxy classes should have zero serialVersionUID", 0,
+                proxyStreamClass.getSerialVersionUID());
+        ObjectStreamField[] proxyFields = proxyStreamClass.getFields();
+        assertEquals("Proxy classes should have no serialized fields", 0,
+                proxyFields.length);
+
+        ObjectStreamClass enumStreamClass = ObjectStreamClass
+                .lookup(Thread.State.class);
+
+        assertEquals("Enum classes should have zero serialVersionUID", 0,
+                enumStreamClass.getSerialVersionUID());
+        ObjectStreamField[] enumFields = enumStreamClass.getFields();
+        assertEquals("Enum classes should have no serialized fields", 0,
+                enumFields.length);
+    }
 }



Mime
View raw message