[kaffe] CVS kaffe (dalibor): Fix for RMI examples from RMI Trail of Sun's Java Tutorial from http://java.sun.

Kaffe CVS cvs-commits at kaffe.org
Fri Aug 22 06:34:02 PDT 2003


PatchSet 3973 
Date: 2003/08/22 13:24:40
Author: dalibor
Branch: HEAD
Tag: (none) 
Log:
Fix for RMI examples from RMI Trail of Sun's Java Tutorial from http://java.sun.com/docs/books/tutorial/rmi/index.html.

RMInputStream loads its classes using java.rmi.server.RMIClassLoader. The class loader should link the classes it loads, otherwise we get crashes.

The rest is a fix for deserialization. Field types are passed as signatures, not class names. That means, it's not such a good idea, to pass them to Class.forName directly. I'm letting the TypeSignature thingy do the work now (like it was in the original Classpath code), but I'm also passing the class loader through, which is supposed to be used to load the classes.

Members: 
	ChangeLog:1.1570->1.1571 
	libraries/javalib/gnu/java/lang/reflect/TypeSignature.java:1.1->1.2 
	libraries/javalib/java/io/ObjectInputStream.java:1.24->1.25 
	libraries/javalib/java/io/ObjectStreamField.java:1.2->1.3 
	libraries/javalib/java/rmi/server/RMIClassLoader.java:1.2->1.3 

Index: kaffe/ChangeLog
diff -u kaffe/ChangeLog:1.1570 kaffe/ChangeLog:1.1571
--- kaffe/ChangeLog:1.1570	Fri Aug 22 12:26:42 2003
+++ kaffe/ChangeLog	Fri Aug 22 13:24:40 2003
@@ -1,5 +1,26 @@
 2003-08-22  Helmer Kraemer  <hkraemer at freenet.de>
 
+	* gnu/java/lang/reflect/TypeSignature.java:
+	(getClassForEncoding) added new method that accepts a class loader
+	and uses it to load and link the requested class.
+	
+	* java/io/ObjectInputStream.java:
+	(readClassDescriptor) Field types are passed as signatures, not
+	class names. That means it's not such a good idea to pass them
+	to Class.forName directly. 
+	(resolveClass) use Class.forName with given class loader. removed
+	resolveClass(String).
+	(currentLoader) new helper method.
+	
+	* java/io/ObjectStreamField.java:
+	(ObjectStreamField) new constructor that accepts a class loader
+	parameter and uses it load the requested type.
+
+	* java/rmi/server/RMIClassLoader.java:
+	(loadClass) link classes that get loaded, otherwise kaffe crashes.
+	
+2003-08-22  Helmer Kraemer  <hkraemer at freenet.de>
+
 	* kaffe/kaffevm/mem/gc-mem.c:
 	(gc_heap_free) properly free empty primitive blocks
 
Index: kaffe/libraries/javalib/gnu/java/lang/reflect/TypeSignature.java
diff -u kaffe/libraries/javalib/gnu/java/lang/reflect/TypeSignature.java:1.1 kaffe/libraries/javalib/gnu/java/lang/reflect/TypeSignature.java:1.2
--- kaffe/libraries/javalib/gnu/java/lang/reflect/TypeSignature.java:1.1	Wed May 21 10:42:29 2003
+++ kaffe/libraries/javalib/gnu/java/lang/reflect/TypeSignature.java	Fri Aug 22 13:24:42 2003
@@ -150,6 +150,12 @@
   public static Class getClassForEncoding(String type_code, boolean descriptor)
     throws ClassNotFoundException
   {
+    return getClassForEncoding(type_code, descriptor, null);
+  }
+
+  public static Class getClassForEncoding(String type_code, boolean descriptor, ClassLoader loader)
+    throws ClassNotFoundException
+  {
     if (descriptor)
       {
         switch (type_code.charAt(0))
@@ -181,7 +187,7 @@
           case '[':
           }
       }
-    return Class.forName(type_code.replace('/', '.'));
+    return Class.forName(type_code.replace('/', '.'), true, loader);
   }
 
   /**
Index: kaffe/libraries/javalib/java/io/ObjectInputStream.java
diff -u kaffe/libraries/javalib/java/io/ObjectInputStream.java:1.24 kaffe/libraries/javalib/java/io/ObjectInputStream.java:1.25
--- kaffe/libraries/javalib/java/io/ObjectInputStream.java:1.24	Wed Aug 20 06:19:16 2003
+++ kaffe/libraries/javalib/java/io/ObjectInputStream.java	Fri Aug 22 13:24:42 2003
@@ -455,21 +455,13 @@
 	if (type_code == 'L' || type_code == '[')
 	{
 	  class_name = (String)readObject ();
-	  /* We need to fully resolve only when an object is concerned.
-	   * in the other case just use TypeSignature
-	   */
-	  if (class_name.charAt(0) == 'L')
-	    of = new ObjectStreamField (field_name,
-		       resolveClass(class_name.substring(1,
-				       class_name.length()-1)));
-	  else
-	    of = new ObjectStreamField (field_name, class_name);
 	}
 	else
 	{
 	  class_name = String.valueOf (type_code);
-	  of = new ObjectStreamField (field_name, class_name);
-	}
+        }
+	
+        of = new ObjectStreamField (field_name, class_name, currentLoader());
 	
 	fields[i] = of;
       }
@@ -592,22 +584,16 @@
   protected Class resolveClass (ObjectStreamClass osc)
     throws ClassNotFoundException, IOException
   {
-    return resolveClass (osc.getName ());
+    return Class.forName (osc.getName(), true, currentLoader()); 
   }
 
-  private Class resolveClass (String class_name)
-	      throws ClassNotFoundException, IOException
+  private ClassLoader currentLoader ()
   {
     SecurityManager sm = System.getSecurityManager ();
     if (sm == null)
       sm = new SecurityManager () {};
 
-    ClassLoader cl = currentClassLoader (sm);
-
-    if (cl == null)
-      return Class.forName (class_name);
-    else
-      return cl.loadClass (class_name);
+    return currentClassLoader (sm);
   }
 
   /* Lookup a class stored in the local hashtable. If it is not
Index: kaffe/libraries/javalib/java/io/ObjectStreamField.java
diff -u kaffe/libraries/javalib/java/io/ObjectStreamField.java:1.2 kaffe/libraries/javalib/java/io/ObjectStreamField.java:1.3
--- kaffe/libraries/javalib/java/io/ObjectStreamField.java:1.2	Mon Aug 11 17:55:45 2003
+++ kaffe/libraries/javalib/java/io/ObjectStreamField.java	Fri Aug 22 13:24:42 2003
@@ -84,6 +84,19 @@
         type = Object.class; //FIXME: ???
       }
   }
+
+  ObjectStreamField (String name, String typename, ClassLoader loader){
+    this.name = name;
+    this.typename = typename;
+    try
+      {
+        type = TypeSignature.getClassForEncoding(typename, true, loader);
+      }
+    catch(ClassNotFoundException e)
+      {
+        type = Object.class; // ALSO FIXME 
+      }
+  }
   
   public String getName ()
   {
Index: kaffe/libraries/javalib/java/rmi/server/RMIClassLoader.java
diff -u kaffe/libraries/javalib/java/rmi/server/RMIClassLoader.java:1.2 kaffe/libraries/javalib/java/rmi/server/RMIClassLoader.java:1.3
--- kaffe/libraries/javalib/java/rmi/server/RMIClassLoader.java:1.2	Mon Aug 18 17:40:36 2003
+++ kaffe/libraries/javalib/java/rmi/server/RMIClassLoader.java	Fri Aug 22 13:24:42 2003
@@ -210,7 +210,7 @@
     //try context class loader first
     try
       {
-      c = loader.loadClass(name);
+      c = Class.forName(name, true, loader);
 
       return c;
       }
@@ -235,7 +235,7 @@
                                        ") at codebase (" + codebases + ")");
       }
       
-    return loader.loadClass(name);
+    return Class.forName(name, true, loader);
     }
 
     /**




More information about the kaffe mailing list