Patch for RMI

Norbert Frese postfach@nfrese.net
Sat Jan 3 15:38:00 GMT 2004


I have found a little problem in the libgcj rmi-classes. When you export
an object via rmi and you specify a distinct port and this port is
already occupied, libgcj just chooses another port without warning you.
This - for instance - is problematic when creating a rmi-registry on an
already used port (a rmi-registry has to use distinct ports).
As far i have investigated sun-rmi it always throws a
java.rmi.server.ExportException when it cannot 'bind' to a certain port.
A testcase is attached.
Norbert
Patch:
Index: gcc/libjava/gnu/java/rmi/server/UnicastConnectionManager.java
===================================================================
RCS file:
/cvs/gcc/gcc/libjava/gnu/java/rmi/server/UnicastConnectionManager.java,v
retrieving revision 1.5
diff -r1.5 UnicastConnectionManager.java
176c176,177
< private UnicastConnectionManager(int port, RMIServerSocketFactory ssf)
{
---
> private UnicastConnectionManager(int port, RMIServerSocketFactory ssf)
throws RemoteException {
>181,189c182,185
< 	catch (IOException _) {
< 		try {
< 			ssock = ssf.createServerSocket(0);
< 			serverPort = ssock.getLocalPort();
< 		}
< 		catch (IOException __) {
< 			ssock = null;
< 			serverPort = 0;
< 		}
---
> 	catch (IOException ioex) {
> 		ssock = null;
> 		serverPort = 0;
> 		throw new java.rmi.server.ExportException("can not create Server
Socket on port " + port,ioex);
233c229
< public static synchronized UnicastConnectionManager getInstance(int
port, RMIServerSocketFactory ssf) {
---
> public static synchronized UnicastConnectionManager getInstance(int
port, RMIServerSocketFactory ssf) throws RemoteException {
Index: gcc/libjava/gnu/java/rmi/server/UnicastServerRef.java
===================================================================
RCS file:
/cvs/gcc/gcc/libjava/gnu/java/rmi/server/UnicastServerRef.java,v
retrieving revision 1.7
diff -r1.7 UnicastServerRef.java
88c88
< public UnicastServerRef(ObjID id, int port, RMIServerSocketFactory
ssf) {
---
> public UnicastServerRef(ObjID id, int port, RMIServerSocketFactory
ssf) throws RemoteException {
-------------- next part --------------
A non-text attachment was scrubbed...
Name: DistinctRMIExportTest.java
Type: text/x-java
Size: 820 bytes
Desc: not available
URL: <http://gcc.gnu.org/pipermail/java/attachments/20040103/ce817afc/attachment.bin>


More information about the Java mailing list

AltStyle によって変換されたページ (->オリジナル) /