[kaffe] CVS kaffe (dalibor): Resynced with GNU Classpath: serialization fixes

Kaffe CVS cvs-commits at kaffe.org
Sun Jul 11 20:47:36 PDT 2004


PatchSet 4942 
Date: 2004/07/12 03:40:55
Author: dalibor
Branch: HEAD
Tag: (none) 
Log:
Resynced with GNU Classpath: serialization fixes

2004-07-11  Dalibor Topic  <robilad at kaffe.org>

        * libraries/javalib/java/io/ObjectInputStream.java,
        libraries/javalib/java/io/ObjectStreamClass.java:
        Resynced with GNU Classpath.

        2004-07-10  Jeroen Frijters  <jeroen at frijters.net>

        * java/io/ObjectInputStream.java (readObject): Delegate instantation
        of Externalizable classes to ObjectStreamClass.
        * java/io/ObjectStreamClass.java (newInstance): New method to
        instantiate Externalizable (while ignoring the accessibility of
        the constructor). (constructor): New field to cache the constructor.

Members: 
	ChangeLog:1.2507->1.2508 
	libraries/javalib/java/io/ObjectInputStream.java:1.37->1.38 
	libraries/javalib/java/io/ObjectStreamClass.java:1.23->1.24 

Index: kaffe/ChangeLog
diff -u kaffe/ChangeLog:1.2507 kaffe/ChangeLog:1.2508
--- kaffe/ChangeLog:1.2507	Mon Jul 12 03:33:30 2004
+++ kaffe/ChangeLog	Mon Jul 12 03:40:55 2004
@@ -14,6 +14,20 @@
 
 2004-07-11  Dalibor Topic  <robilad at kaffe.org>
 
+	* libraries/javalib/java/io/ObjectInputStream.java,
+	libraries/javalib/java/io/ObjectStreamClass.java:
+	Resynced with GNU Classpath.
+
+	2004-07-10  Jeroen Frijters  <jeroen at frijters.net>
+
+        * java/io/ObjectInputStream.java (readObject): Delegate instantation
+        of Externalizable classes to ObjectStreamClass.
+        * java/io/ObjectStreamClass.java (newInstance): New method to
+        instantiate Externalizable (while ignoring the accessibility of
+        the constructor). (constructor): New field to cache the constructor.
+
+2004-07-11  Dalibor Topic  <robilad at kaffe.org>
+
 	*  libraries/javalib/java/io/BufferedInputStream.java:
 	Resynced with GNU Classpath.
 
Index: kaffe/libraries/javalib/java/io/ObjectInputStream.java
diff -u kaffe/libraries/javalib/java/io/ObjectInputStream.java:1.37 kaffe/libraries/javalib/java/io/ObjectInputStream.java:1.38
--- kaffe/libraries/javalib/java/io/ObjectInputStream.java:1.37	Thu Jun  3 21:57:05 2004
+++ kaffe/libraries/javalib/java/io/ObjectInputStream.java	Mon Jul 12 03:40:58 2004
@@ -275,29 +275,7 @@
 	      
 	      if (osc.realClassIsExternalizable)
 		{
-		  Externalizable obj = null;
-		  
-		  try
-		    {
-		      obj = (Externalizable)clazz.newInstance();
-		    }
-		  catch (InstantiationException e)
-		    {
-		      throw new ClassNotFoundException
-			("Instance of " + clazz + " could not be created");
-		    }
-		  catch (IllegalAccessException e)
-		    {
-		      throw new ClassNotFoundException
-			("Instance of " + clazz + " could not be created because class or "
-			 + "zero-argument constructor is not accessible");
-		    }
-		  catch (NoSuchMethodError e)
-		    {
-		      throw new ClassNotFoundException
-			("Instance of " + clazz
-			 + " could not be created because zero-argument constructor is not defined");
-		    }
+		  Externalizable obj = osc.newInstance();
 		  
 		  int handle = assignNewHandle(obj);
 		  
Index: kaffe/libraries/javalib/java/io/ObjectStreamClass.java
diff -u kaffe/libraries/javalib/java/io/ObjectStreamClass.java:1.23 kaffe/libraries/javalib/java/io/ObjectStreamClass.java:1.24
--- kaffe/libraries/javalib/java/io/ObjectStreamClass.java:1.23	Tue May 18 03:35:07 2004
+++ kaffe/libraries/javalib/java/io/ObjectStreamClass.java	Mon Jul 12 03:40:58 2004
@@ -833,6 +833,54 @@
     return fieldsArray;
   }
 
+  /**
+   * Returns a new instance of the Class this ObjectStreamClass corresponds
+   * to.
+   * Note that this should only be used for Externalizable classes.
+   *
+   * @return A new instance.
+   */
+  Externalizable newInstance() throws InvalidClassException
+  {
+    synchronized(this)
+    {
+	if (constructor == null)
+	{
+	    try
+	    {
+		final Constructor c = clazz.getConstructor(new Class[0]);
+
+		AccessController.doPrivileged(new PrivilegedAction()
+		{
+		    public Object run()
+		    {
+			c.setAccessible(true);
+			return null;
+		    }
+		});
+
+		constructor = c;
+	    }
+	    catch(NoSuchMethodException x)
+	    {
+		throw new InvalidClassException(clazz.getName(),
+		    "No public zero-argument constructor");
+	    }
+	}
+    }
+
+    try
+    {
+	return (Externalizable)constructor.newInstance(null);
+    }
+    catch(Throwable t)
+    {
+	throw (InvalidClassException)
+	    new InvalidClassException(clazz.getName(),
+		     "Unable to instantiate").initCause(t);
+    }
+  }
+
   public static final ObjectStreamField[] NO_FIELDS = {};
 
   private static Hashtable classLookupTable = new Hashtable();
@@ -862,6 +910,7 @@
   boolean realClassIsExternalizable;
   ObjectStreamField[] fieldMapping;
   Class firstNonSerializableParent;
+  private Constructor constructor;  // default constructor for Externalizable
 
   boolean isProxyClass = false;
 




More information about the kaffe mailing list