test/jdk/java/net/SocketImpl/BadUsages.java
branchniosocketimpl-branch
changeset 57341 733e9746d615
parent 57340 9026cb618cdd
child 58679 9c3209ff7550
--- a/test/jdk/java/net/SocketImpl/BadUsages.java	Fri Apr 26 11:31:38 2019 +0100
+++ b/test/jdk/java/net/SocketImpl/BadUsages.java	Mon Apr 29 09:03:06 2019 +0100
@@ -118,13 +118,14 @@
      * Test connect when already connected.
      */
     public void testConnect4() throws IOException {
-        try (var ss = new ServerSocket(0);
+        try (var ss = new ServerSocket();
              var impl = new PlatformSocketImpl(false)) {
+            var loopback = InetAddress.getLoopbackAddress();
+            ss.bind(new InetSocketAddress(loopback, 0));
             impl.create(true);
-            String host = ss.getInetAddress().getHostAddress();
             int port = ss.getLocalPort();
-            impl.connect(host, port);
-            expectThrows(IOException.class, () -> impl.connect(host, port));
+            impl.connect(loopback, port);
+            expectThrows(IOException.class, () -> impl.connect(loopback, port));
         }
     }
 
@@ -166,11 +167,12 @@
      * Test bind when connected.
      */
     public void testBind3() throws IOException {
-        try (var ss = new ServerSocket(0);
+        try (var ss = new ServerSocket();
              var impl = new PlatformSocketImpl(false)) {
+            var loopback = InetAddress.getLoopbackAddress();
+            ss.bind(new InetSocketAddress(loopback, 0));
             impl.create(true);
             impl.connect(ss.getLocalSocketAddress(), 0);
-            var loopback = InetAddress.getLoopbackAddress();
             expectThrows(IOException.class, () -> impl.bind(loopback, 0));
         }
     }