test/java/rmi/Naming/LookupIPv6.java

Print this page

        

@@ -23,11 +23,12 @@
 
 /* @test
  * @summary Ensure that java.rmi.Naming.lookup can handle URLs containing
  *          IPv6 addresses.
  * @bug 4402708
- *
+ * @library ../testlibrary
+ * @build TestLibrary
  * @run main/othervm -Djava.net.preferIPv6Addresses=true LookupIPv6
  */
 
 import java.net.InetAddress;
 import java.net.Inet6Address;

@@ -35,10 +36,12 @@
 import java.rmi.Naming;
 import java.rmi.registry.LocateRegistry;
 import java.rmi.registry.Registry;
 
 public class LookupIPv6 {
+    private static final int REGISTRY_PORT = TestLibrary.getUnusedRandomPort();
+    
     public static void main(String[] args) throws Exception {
         // use loopback IPv6 address to avoid lengthy socket connection delays
         String[] urls = {
             "rmi://[0000:0000:0000:0000:0000:0000:0000:0001]/foo",
             "//[0:0:0:0:0:0:0:1]:88/foo",

@@ -65,14 +68,14 @@
         InetAddress localAddr = InetAddress.getAllByName(null)[0];
         if (localAddr instanceof Inet6Address) {
             System.out.println("IPv6 detected");
             Registry reg;
             try {
-                reg = LocateRegistry.createRegistry(Registry.REGISTRY_PORT);
+                reg = LocateRegistry.createRegistry(REGISTRY_PORT);
             } catch (Exception ex) {
                 reg = LocateRegistry.getRegistry();
             }
             reg.rebind("foo", reg);
-            Naming.lookup("rmi://[" + localAddr.getHostAddress() + "]/foo");
+            Naming.lookup("rmi://[" + localAddr.getHostAddress() + "]" + ":" + REGISTRY_PORT + "/foo");
         }
     }
 }