changeset 9945:5d191d40073f

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
author dsamersoff
date Thu, 22 May 2014 13:03:10 -0700
parents ae3f2b31bb3c
children af9c7dccd0f6 069b9bde2729
files src/share/classes/com/sun/tools/jdi/SocketAttachingConnector.java src/share/classes/com/sun/tools/jdi/SocketTransportService.java src/share/transport/socket/socketTransport.c test/com/sun/jdi/BadHandshakeTest.java test/com/sun/jdi/RunToExit.java
diffstat 5 files changed, 14 insertions(+), 11 deletions(-) [+]
line wrap: on
line diff
--- a/src/share/classes/com/sun/tools/jdi/SocketAttachingConnector.java	Thu May 22 20:19:08 2014 +0400
+++ b/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/src/share/classes/com/sun/tools/jdi/SocketTransportService.java	Thu May 22 20:19:08 2014 +0400
+++ b/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/src/share/transport/socket/socketTransport.c	Thu May 22 20:19:08 2014 +0400
+++ b/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/test/com/sun/jdi/BadHandshakeTest.java	Thu May 22 20:19:08 2014 +0400
+++ b/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/test/com/sun/jdi/RunToExit.java	Thu May 22 20:19:08 2014 +0400
+++ b/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