RFR: 8022445: fix RMISocketFactory example to avoid using localhost

Stuart Marks stuart.marks at oracle.com
Thu Aug 22 00:58:31 UTC 2013


Hi all,

Please review this small documentation change to the example I added to 
RMISocketFactory a couple weeks ago [1]. This change fixes a problem 
that Bernd Eckenfels pointed out [2] where the interface returned by 
getLoopbackAddress() might not match the interface that "localhost" 
resolves to.

Patch appended below.

Thanks,

s'marks

[1] http://hg.openjdk.java.net/jdk8/tl/jdk/rev/31759750ff63

[2] 
http://mail.openjdk.java.net/pipermail/security-dev/2013-August/008346.html



# HG changeset patch
# User smarks
# Date 1377131500 25200
# Node ID fac7907d8c0b4358b9994b04562b722f533db3ac
# Parent  1ccc7bbee0bb4d4d0f472374f2cc544cb07d1336
8022445: fix RMISocketFactory example to avoid using localhost
Reviewed-by: XXX

diff -r 1ccc7bbee0bb -r fac7907d8c0b 
src/share/classes/java/rmi/server/RMISocketFactory.java
--- a/src/share/classes/java/rmi/server/RMISocketFactory.java	Tue Aug 20 
11:15:08 2013 +0200
+++ b/src/share/classes/java/rmi/server/RMISocketFactory.java	Wed Aug 21 
17:31:40 2013 -0700
@@ -50,13 +50,13 @@
   * @implNote
   * <p>You can use the {@code RMISocketFactory} class to create a 
server socket that
   * is bound to a specific address, restricting the origin of requests. 
For example,
- * the following code implements a socket factory that binds server 
sockets to the
+ * the following code implements a socket factory that binds server 
sockets to the IPv6
   * loopback address. This restricts RMI to processing requests only 
from the local host.
   *
   * <pre>{@code
   *     class LoopbackSocketFactory extends RMISocketFactory {
   *         public ServerSocket createServerSocket(int port) throws 
IOException {
- *             return new ServerSocket(port, 5, 
InetAddress.getLoopbackAddress());
+ *             return new ServerSocket(port, 5, 
InetAddress.getByName("::1"));
   *         }
   *
   *         public Socket createSocket(String host, int port) throws 
IOException {
@@ -72,8 +72,8 @@
   * }</pre>
   *
   * Set the {@code java.rmi.server.hostname} system property
- * to a host name (typically {@code localhost}) that resolves to the 
loopback
- * interface to ensure that the generated stubs use the right network 
interface.
+ * to {@code ::1} to ensure that the generated stubs connect to the right
+ * network interface.
   *
   * @author  Ann Wollrath
   * @author  Peter Jones



More information about the core-libs-dev mailing list