8043716: JDI test com/sun/jdi/ProcessAttachTest.sh and other 3 jdi tests failed in nightly
authordsamersoff
Thu, 22 May 2014 13:03:10 -0700
changeset 24514 2440b44952d7
parent 24513 2b9212fa87d8
child 24515 7cef268493b1
child 24578 bbf15045dfbb
8043716: JDI test com/sun/jdi/ProcessAttachTest.sh and other 3 jdi tests failed in nightly Summary: InetAddress.getLocalHost() returns configured host name instead of localhost. Reviewed-by: dcubed
jdk/src/share/classes/com/sun/tools/jdi/SocketAttachingConnector.java
jdk/src/share/classes/com/sun/tools/jdi/SocketTransportService.java
jdk/src/share/transport/socket/socketTransport.c
jdk/test/com/sun/jdi/BadHandshakeTest.java
jdk/test/com/sun/jdi/RunToExit.java
--- a/jdk/src/share/classes/com/sun/tools/jdi/SocketAttachingConnector.java	Thu May 22 20:19:08 2014 +0400
+++ b/jdk/src/share/classes/com/sun/tools/jdi/SocketAttachingConnector.java	Thu May 22 13:03:10 2014 -0700
@@ -44,12 +44,7 @@
     public SocketAttachingConnector() {
         super(new SocketTransportService());
 
-        String defaultHostName;
-        try {
-            defaultHostName = InetAddress.getLocalHost().getHostName();
-        } catch (UnknownHostException e) {
-            defaultHostName = "";
-        }
+        String defaultHostName = "localhost";
 
         addStringArgument(
             ARG_HOST,
--- a/jdk/src/share/classes/com/sun/tools/jdi/SocketTransportService.java	Thu May 22 20:19:08 2014 +0400
+++ b/jdk/src/share/classes/com/sun/tools/jdi/SocketTransportService.java	Thu May 22 13:03:10 2014 -0700
@@ -198,13 +198,17 @@
         String host;
         String portStr;
         if (splitIndex < 0) {
-            host = InetAddress.getLocalHost().getHostName();
+            host = "localhost";
             portStr = address;
         } else {
             host = address.substring(0, splitIndex);
             portStr = address.substring(splitIndex+1);
         }
 
+        if (host.equals("*")) {
+            host = InetAddress.getLocalHost().getHostName();
+        }
+
         int port;
         try {
             port = Integer.decode(portStr).intValue();
@@ -215,7 +219,6 @@
 
 
         // open TCP connection to VM
-
         InetSocketAddress sa = new InetSocketAddress(host, port);
         Socket s = new Socket();
         try {
--- a/jdk/src/share/transport/socket/socketTransport.c	Thu May 22 20:19:08 2014 +0400
+++ b/jdk/src/share/transport/socket/socketTransport.c	Thu May 22 13:03:10 2014 -0700
@@ -199,9 +199,11 @@
     // Simple routine to guess localhost address.
     // it looks up "localhost" and returns 127.0.0.1 if lookup
     // fails.
-    struct addrinfo hints = {0}, *res = NULL;
+    struct addrinfo hints, *res = NULL;
     int err;
 
+    // Use portable way to initialize the structure
+    memset((void *)&hints, 0, sizeof(hints));
     hints.ai_family = AF_INET;
 
     err = getaddrinfo("localhost", NULL, &hints, &res);
--- a/jdk/test/com/sun/jdi/BadHandshakeTest.java	Thu May 22 20:19:08 2014 +0400
+++ b/jdk/test/com/sun/jdi/BadHandshakeTest.java	Thu May 22 13:03:10 2014 -0700
@@ -110,12 +110,12 @@
         }
 
         // Connect to the debuggee and handshake with garbage
-        Socket s = new Socket(InetAddress.getLocalHost(), port);
+        Socket s = new Socket("localhost", port);
         s.getOutputStream().write("Here's a poke in the eye".getBytes("UTF-8"));
         s.close();
 
         // Re-connect and to a partial handshake - don't disconnect
-        s = new Socket(InetAddress.getLocalHost(), port);
+        s = new Socket("localhost", port);
         s.getOutputStream().write("JDWP-".getBytes("UTF-8"));
 
 
--- a/jdk/test/com/sun/jdi/RunToExit.java	Thu May 22 20:19:08 2014 +0400
+++ b/jdk/test/com/sun/jdi/RunToExit.java	Thu May 22 13:03:10 2014 -0700
@@ -161,6 +161,9 @@
         Connector.IntegerArgument port_arg =
             (Connector.IntegerArgument)conn_args.get("port");
         port_arg.setValue(port);
+
+        System.out.println("Connection arguments: " + conn_args);
+
         VirtualMachine vm = conn.attach(conn_args);
 
         // The first event is always a VMStartEvent, and it is always in