jdk/src/share/classes/sun/security/ssl/SSLSocketImpl.java
changeset 2068 cdbc5929b91e
parent 1763 0a6b65d56746
child 5162 0dbedf4fdb8c
child 5182 62836694baeb
--- a/jdk/src/share/classes/sun/security/ssl/SSLSocketImpl.java	Mon Feb 23 10:05:55 2009 +0800
+++ b/jdk/src/share/classes/sun/security/ssl/SSLSocketImpl.java	Mon Feb 23 17:32:52 2009 +0800
@@ -1,5 +1,5 @@
 /*
- * Copyright 1996-2008 Sun Microsystems, Inc.  All Rights Reserved.
+ * Copyright 1996-2009 Sun Microsystems, Inc.  All Rights Reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -368,7 +368,9 @@
         super();
         this.host = host;
         init(context, false);
-        SocketAddress socketAddress = new InetSocketAddress(host, port);
+        SocketAddress socketAddress =
+               host != null ? new InetSocketAddress(host, port) :
+               new InetSocketAddress(InetAddress.getByName(null), port);
         connect(socketAddress, 0);
     }
 
@@ -409,7 +411,9 @@
         this.host = host;
         init(context, false);
         bind(new InetSocketAddress(localAddr, localPort));
-        SocketAddress socketAddress = new InetSocketAddress(host, port);
+        SocketAddress socketAddress =
+               host != null ? new InetSocketAddress(host, port) :
+               new InetSocketAddress(InetAddress.getByName(null), port);
         connect(socketAddress, 0);
     }
 
@@ -1829,7 +1833,8 @@
     }
 
     synchronized String getHost() {
-        if (host == null) {
+        // Note that the host may be null or empty for localhost.
+        if (host == null || host.length() == 0) {
             host = getInetAddress().getHostName();
         }
         return host;