Hi,

The RMI server code does not propagate Errors to RMI clients.
I found why. There are two bugs:
1. UnicastServerRef.incomingMessageCall casts 
   InvocationTargetException.getTargetException () to Exception. 
   It fails when getTargetException () returns an Error.
2. UnicastServer.incomingMessageCall does not have a handler for Errors.
   According to RMI spec. Errors in a remote method should be caught,
   wrapped in ServerError and send to the client.
I fixed these bugs. A patch is attached. Can somebody apply it?
Also, please close my bug report
http://savannah.gnu.org/bugs/?func=detailitem&item_id=10315

Regards, 
Ilya
Index: gnu/java/rmi/server/UnicastServer.java
===================================================================
RCS file: /cvsroot/classpath/classpath/gnu/java/rmi/server/UnicastServer.java,v
retrieving revision 1.6
diff -u -r1.6 UnicastServer.java
--- gnu/java/rmi/server/UnicastServer.java	21 Mar 2004 10:10:14 -0000	1.6
+++ gnu/java/rmi/server/UnicastServer.java	12 Sep 2004 00:51:04 -0000
@@ -46,6 +46,7 @@
 import java.util.Hashtable;
 import java.net.UnknownHostException;
 import java.rmi.Remote;
+import java.rmi.ServerError;
 import java.rmi.server.ObjID;
 import java.rmi.server.UnicastRemoteObject;
 import java.rmi.server.UID;
@@ -136,6 +137,10 @@
 			returnval = e;
 			returncode = RETURN_NACK;
 		}
+                catch (Error e) {
+			returnval = new ServerError ("An Error is thrown while processing the invocation on the server", e);
+			returncode = RETURN_NACK;
+                }
 	}
 	else {
 		returnval = new NoSuchObjectException("");
Index: gnu/java/rmi/server/UnicastServerRef.java
===================================================================
RCS file: /cvsroot/classpath/classpath/gnu/java/rmi/server/UnicastServerRef.java,v
retrieving revision 1.9
diff -u -r1.9 UnicastServerRef.java
--- gnu/java/rmi/server/UnicastServerRef.java	21 Mar 2004 10:10:14 -0000	1.9
+++ gnu/java/rmi/server/UnicastServerRef.java	12 Sep 2004 00:51:04 -0000
@@ -284,7 +284,16 @@
 		try{
 		    ret = meth.invoke(myself, args);
 		}catch(InvocationTargetException e){
-		    throw (Exception)(e.getTargetException());
+                    Throwable cause = e.getTargetException();
+                    if (cause instanceof Exception) {
+                        throw (Exception)cause;
+                    }
+                    else if (cause instanceof Error) {
+                        throw (Error)cause;
+                    }
+                    else {
+                        throw new Error("The remote method threw a java.lang.Throwable that is neither java.lang.Exception nor java.lang.Error.", e);
+                    }
 		}
 		return ret;
 	}


_______________________________________________
Classpath mailing list
[EMAIL PROTECTED]
http://lists.gnu.org/mailman/listinfo/classpath

Reply via email to