8071424: JCK test api/java_net/Socket/descriptions.html#Bind crashes on Windows
authorchegar
Mon, 26 Jan 2015 13:46:08 +0000
changeset 28663 5bedcbb25c5f
parent 28662 efd0203db371
child 28664 2f79ecb05ada
8071424: JCK test api/java_net/Socket/descriptions.html#Bind crashes on Windows Reviewed-by: alanb
jdk/src/java.base/windows/native/libnet/DualStackPlainSocketImpl.c
jdk/test/java/net/Socket/GetLocalAddress.java
--- a/jdk/src/java.base/windows/native/libnet/DualStackPlainSocketImpl.c	Mon Jan 26 18:13:42 2015 +0800
+++ b/jdk/src/java.base/windows/native/libnet/DualStackPlainSocketImpl.c	Mon Jan 26 13:46:08 2015 +0000
@@ -48,6 +48,8 @@
     isa_ctorID = (*env)->GetMethodID(env, cls, "<init>",
                                      "(Ljava/net/InetAddress;I)V");
 
+    initInetAddressIDs(env);
+
     // implement read timeout with select.
     isRcvTimeoutSupported = 0;
 }
--- a/jdk/test/java/net/Socket/GetLocalAddress.java	Mon Jan 26 18:13:42 2015 +0800
+++ b/jdk/test/java/net/Socket/GetLocalAddress.java	Mon Jan 26 13:46:08 2015 +0000
@@ -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,18 @@
         }
     }
 
+    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");
+        }
+    }
 }