[kaffe] CVS kaffe (robilad): Resynced with GNU classpath: serialization fix

Kaffe CVS cvs-commits at kaffe.org
Mon Jul 4 08:49:26 PDT 2005


PatchSet 6696 
Date: 2005/07/04 15:37:32
Author: robilad
Branch: HEAD
Tag: (none) 
Log:
Resynced with GNU classpath: serialization fix

2005-07-04  Dalibor Topic  <robilad at kaffe.org>

        Resynced with GNU Classpath.

        2005-07-03  Daniel Bonniot  <bonniot at users.sf.net>

        * java/io/ObjectStreamClass.java (inSamePackage): New private method.
        (findAccessibleMethod): Likewise.
        (cacheMethods): Lookup readResolve and writeReplace using the new
        findAccessibleMethod().

Members: 
	ChangeLog:1.4220->1.4221 
	libraries/javalib/java/io/ObjectStreamClass.java:1.31->1.32 

Index: kaffe/ChangeLog
diff -u kaffe/ChangeLog:1.4220 kaffe/ChangeLog:1.4221
--- kaffe/ChangeLog:1.4220	Mon Jul  4 15:29:52 2005
+++ kaffe/ChangeLog	Mon Jul  4 15:37:32 2005
@@ -2,6 +2,17 @@
 
 	Resynced with GNU Classpath.
 
+	2005-07-03  Daniel Bonniot  <bonniot at users.sf.net>
+
+        * java/io/ObjectStreamClass.java (inSamePackage): New private method.
+        (findAccessibleMethod): Likewise.
+        (cacheMethods): Lookup readResolve and writeReplace using the new
+        findAccessibleMethod().
+
+2005-07-04  Dalibor Topic  <robilad at kaffe.org>
+
+	Resynced with GNU Classpath.
+
 	2005-07-03  Audrius Meskauskas, <AudriusA at Bioinformatics.org>
 
         * org/omg/PortableServer/ServantLocatorPackage/package.html,
Index: kaffe/libraries/javalib/java/io/ObjectStreamClass.java
diff -u kaffe/libraries/javalib/java/io/ObjectStreamClass.java:1.31 kaffe/libraries/javalib/java/io/ObjectStreamClass.java:1.32
--- kaffe/libraries/javalib/java/io/ObjectStreamClass.java:1.31	Mon Jul  4 00:06:37 2005
+++ kaffe/libraries/javalib/java/io/ObjectStreamClass.java	Mon Jul  4 15:37:36 2005
@@ -486,19 +486,65 @@
     return null;
   }
 
+  private static boolean inSamePackage(Class c1, Class c2)
+  {
+    String name1 = c1.getName();
+    String name2 = c2.getName();
+
+    int id1 = name1.lastIndexOf('.');
+    int id2 = name2.lastIndexOf('.');
+
+    // Handle the default package
+    if (id1 == -1 || id2 == -1)
+      return id1 == id2;
+
+    String package1 = name1.substring(0, id1);
+    String package2 = name2.substring(0, id2);
+
+    return package1.equals(package2);
+  }
+
+  final static Class[] noArgs = new Class[0];
+
+  private static Method findAccessibleMethod(String name, Class from)
+  {
+    for (Class c = from; c != null; c = c.getSuperclass())
+      {
+	try
+	  {
+	    Method res = c.getDeclaredMethod(name, noArgs);
+	    int mods = res.getModifiers();
+
+	    if (c != from
+		&& (Modifier.isPrivate(mods)
+		    || ! Modifier.isPublic(mods) && ! inSamePackage(c, from)))
+	      continue;
+
+	    return res;
+	  }
+	catch (NoSuchMethodException e)
+	  {
+	  }
+      }
+
+    return null;
+  }
+
   private void cacheMethods()
   {
     Method[] methods = forClass().getDeclaredMethods();
+
     readObjectMethod = findMethod(methods, "readObject",
 				  new Class[] { ObjectInputStream.class },
 				  Void.TYPE, true);
     writeObjectMethod = findMethod(methods, "writeObject",
                                    new Class[] { ObjectOutputStream.class },
                                    Void.TYPE, true);
-    readResolveMethod = findMethod(methods, "readResolve",
-				   new Class[0], Object.class, false);
-    writeReplaceMethod = findMethod(methods, "writeReplace",
-                                    new Class[0], Object.class, false);
+
+    // readResolve and writeReplace can be in parent classes, as long as they
+    // are accessible from this class.
+    readResolveMethod = findAccessibleMethod("readResolve", forClass());
+    writeReplaceMethod = findAccessibleMethod("writeReplace", forClass());
   }
 
   private ObjectStreamClass(Class cl)




More information about the kaffe mailing list