Code Review Request 7142596: RMI JPRT tests are failing

Darryl Mocek darryl.mocek at
Mon Jul 16 22:56:00 UTC 2012

Hi Alan.  The reason we didn't go this route is that we want to be able 
to create the RMI Registry on a random port which is not one of the 
reserved ports (see TestLibrary.FIXED_PORT_MIN/MAX).  To do this, we use 
'new ServerSocket(0)', which creates a socket on a random port, then 
close the port, check if it's a 'reserved' port, and return the port 
number if it's not.  Since we have to go through this process anyway, 
the current implementation (see webrev05: already works and 
has broader applicability (e.g. this also supports getting a random port 
for tests which require a socket rather then hard-coding port numbers 
into tests, although this change isn't in this webrev).


On 07/14/2012 03:31 AM, Alan Bateman wrote:
> On 14/07/2012 00:09, Stuart Marks wrote:
>> There is at least one test case that wants to create two registries 
>> within the same JVM. The first call to createRegistry(0) will usually 
>> succeed. The second call from the same JVM will throw an 
>> ExportException. So, we catch this and retry using a random port 
>> instead to create the second registry. If *that* fails we give up at 
>> that point instead of retrying repeatedly.
> Okay, so it's the export of the object that is the issue because the 
> objID is based on the argument rather than the actual port. In that 
> case would it make sense to switch to the factory method that takes 
> the RMIServerSocketFactory as argument, something like:
>   static class ServerSocketFactory implements RMIServerSocketFactory {
>     public ServerSocket createServerSocket(int port) throws 
> IOException { return new ServerSocket(0); }
>   }
>   static class ClientSocketFactory implements RMIClientSocketFactory {
>     public Socket createSocket(String host, int port) throws 
> IOException { return new Socket(host, port); }
>   }
>   Registry registry = LocateRegistry.createRegistry(0, new 
> ClientSocketFactory(), new ServerSocketFactory());
> -Alan.

More information about the core-libs-dev mailing list