test/jdk/java/net/ipv6tests/B6521014.java
changeset 55649 ad8e3b295615
parent 55375 96c7427456f9
child 58679 9c3209ff7550
--- a/test/jdk/java/net/ipv6tests/B6521014.java	Wed Jul 10 16:45:28 2019 +0000
+++ b/test/jdk/java/net/ipv6tests/B6521014.java	Wed Jul 10 22:33:23 2019 +0200
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2007, 2013, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2007, 2019, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -71,7 +71,7 @@
     }
 
     static void test1(Inet6Address sin) throws Exception {
-        try (ServerSocket ssock = new ServerSocket(0);
+        try (ServerSocket ssock = createBoundServer(sin);
              Socket sock = new Socket()) {
             int port = ssock.getLocalPort();
             sock.connect(new InetSocketAddress(sin, port), 100);
@@ -82,7 +82,7 @@
     }
 
     static void test2(Inet6Address sin) throws Exception {
-        try (ServerSocket ssock = new ServerSocket(0);
+        try (ServerSocket ssock = createBoundServer(sin);
              Socket sock = new Socket()) {
             int port = ssock.getLocalPort();
             ssock.setSoTimeout(100);
@@ -94,6 +94,13 @@
         }
     }
 
+    static ServerSocket createBoundServer(Inet6Address sin) throws IOException {
+        ServerSocket ss = new ServerSocket();
+        InetSocketAddress address = new InetSocketAddress(sin, 0);
+        ss.bind(address);
+        return ss;
+    }
+
     public static void main(String[] args) throws Exception {
         Optional<Inet6Address> oaddr = getLocalAddr();
         if (!oaddr.isPresent()) {