Summary
-------
The implementation of InetSocketAddress::toString is changed to improve handling of IPv6 and unresolved addresses. The API documentation of the method is changed accordingly.
Problem
-------
InetSocketAddress::toString is specified to concatenate the result of InetAddress::toString with a colon and the port number. This should print something like: `hostname/IP-literal:port`, for instance `www.example.com/93.184.216.34:80`, where hostname could be an empty string. For IPv6 addresses, this is not desirable as users expect the IPv6 literal to be enclosed in brackets in the manner specified by [RFC 2732][1].
Additionally, the format currently specified for unresolved addresses does not obey the above formatting, which could lead to further confusion.
Solution
--------
In InetSocketAddress::toString:
<br>
1. enclose IPv6 literals in brackets in the manner of RFC 2732.
<br>
2. replace the IP literal with the token `<unresolved>` if InetSocketAddress is unresolved.
Examples:
`InetSocketAddress.createUnresolved("foo", 80).toString()` returns
<br> before: `foo:80`
<br> after: `foo/<unresolved>:80`
`new InetSocketAddress("::1", 80).toString()` returns
<br> before: `/0:0:0:0:0:0:0:1:80`
<br> after: `/[0:0:0:0:0:0:0:1]:80`
Specification
-------------
InetSocketAddress::toString
/**
* Constructs a string representation of this InetSocketAddress.
* This String is constructed by calling toString() on the InetAddress
* and concatenating the port number (with a colon). If the address
- * is unresolved then the part before the colon will only contain the hostname.
+ * is an IPv6 address, the IPv6 literal is enclosed in square brackets.
+ * If the address is {@linkplain #isUnresolved() unresolved},
+ * {@code <unresolved>} is displayed in place of the address literal.
*
* @return a string representation of this object.
*/
@Override
public String toString() {
For reference, the webrev can be found here: http://cr.openjdk.java.net/~jboes/webrevs/8225499/webrev.00/
[1]: https://tools.ietf.org/html/rfc2732 "RFC2732"