summaryrefslogtreecommitdiffstats
path: root/libjava/classpath/java/net/InetSocketAddress.java
diff options
context:
space:
mode:
Diffstat (limited to 'libjava/classpath/java/net/InetSocketAddress.java')
-rw-r--r--libjava/classpath/java/net/InetSocketAddress.java9
1 files changed, 6 insertions, 3 deletions
diff --git a/libjava/classpath/java/net/InetSocketAddress.java b/libjava/classpath/java/net/InetSocketAddress.java
index 91254575265..5267cc11a5d 100644
--- a/libjava/classpath/java/net/InetSocketAddress.java
+++ b/libjava/classpath/java/net/InetSocketAddress.java
@@ -86,7 +86,6 @@ public class InetSocketAddress extends SocketAddress
this.addr = addr;
this.port = port;
- this.hostname = addr.getHostName();
}
/**
@@ -186,7 +185,7 @@ public class InetSocketAddress extends SocketAddress
if (addr == null && sa.addr != null)
return false;
- else if (addr == null && sa.addr == null)
+ else if (addr == null && sa.addr == null) // we know hostname != null
return hostname.equals(sa.hostname) && sa.port == port;
else
return addr.equals(sa.addr) && sa.port == port;
@@ -213,6 +212,9 @@ public class InetSocketAddress extends SocketAddress
*/
public final String getHostName()
{
+ if (hostname == null) // we know addr != null
+ hostname = addr.getHostName();
+
return hostname;
}
@@ -249,10 +251,11 @@ public class InetSocketAddress extends SocketAddress
/**
* Returns the <code>InetSocketAddress</code> as string
*
- * @return A string represenation of this address.
+ * @return A string representation of this address.
*/
public String toString()
{
+ // Note: if addr is null, then hostname != null.
return (addr == null ? hostname : addr.toString()) + ":" + port;
}
}
OpenPOWER on IntegriCloud