test/java/net/Socket/GetLocalAddress.java
Print this page
@@ -21,11 +21,11 @@
* questions.
*/
/*
* @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
* @summary Test the java.net.socket.GetLocalAddress method
*
@@ -37,10 +37,12 @@
static ServerSocket ss;
static InetAddress addr;
static int port;
public static void main(String args[]) throws Exception {
+ testBindNull();
+
boolean error = true;
int linger = 65546;
int value = 0;
addr = InetAddress.getLocalHost();
ss = new ServerSocket(0);
@@ -64,6 +66,20 @@
} catch (Exception e) {
e.printStackTrace();
}
}
+ 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");
+ }
+ }
}