changeset 12394:bc2200a99cac

8071424: JCK test api/java_net/Socket/descriptions.html#Bind crashes on Windows Reviewed-by: alanb
author chegar
date Tue, 27 Jun 2017 14:00:39 +0100
parents 8928a3493a05
children 0209cfe97e57
files src/windows/native/java/net/DualStackPlainSocketImpl.c test/java/net/Socket/GetLocalAddress.java
diffstat 2 files changed, 19 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/src/windows/native/java/net/DualStackPlainSocketImpl.c	Tue Jun 27 13:57:47 2017 +0100
+++ b/src/windows/native/java/net/DualStackPlainSocketImpl.c	Tue Jun 27 14:00:39 2017 +0100
@@ -48,6 +48,7 @@
     isa_ctorID = (*env)->GetMethodID(env, cls, "<init>",
                                      "(Ljava/net/InetAddress;I)V");
     CHECK_NULL(isa_ctorID);
+    initInetAddressIDs(env);
 
     // implement read timeout with select.
     isRcvTimeoutSupported = 0;
--- a/test/java/net/Socket/GetLocalAddress.java	Tue Jun 27 13:57:47 2017 +0100
+++ b/test/java/net/Socket/GetLocalAddress.java	Tue Jun 27 14:00:39 2017 +0100
@@ -23,7 +23,7 @@
 
 /*
  * @test
- * @bug 4106601 8026245
+ * @bug 4106601 8026245 8071424
  * @run main/othervm GetLocalAddress
  * @run main/othervm -Djava.net.preferIPv4Stack=true GetLocalAddress
  * @run main/othervm -Djava.net.preferIPv6Addresses=true GetLocalAddress
@@ -39,6 +39,8 @@
     static int port;
 
     public static void main(String args[]) throws Exception {
+        testBindNull();
+
         boolean      error = true;
         int          linger = 65546;
         int          value = 0;
@@ -66,4 +68,19 @@
         }
     }
 
+    static void testBindNull() throws Exception {
+        try (Socket soc = new Socket()) {
+            soc.bind(null);
+            if (!soc.isBound())
+                throw new RuntimeException(
+                    "should be bound after bind(null)");
+            if (soc.getLocalPort() <= 0)
+                throw new RuntimeException(
+                   "bind(null) failed, local port: " + soc.getLocalPort());
+            if (soc.getLocalAddress() == null)
+                 throw new RuntimeException(
+                   "bind(null) failed, local address is null");
+        }
+    }
+
 }