JDK-8232002 : InetSocketAddress::toString not friendly to IPv6 literal addresses
  • Type: CSR
  • Component: core-libs
  • Sub-Component: java.net
  • Priority: P3
  • Status: Closed
  • Resolution: Approved
  • Fix Versions: 14
  • Submitted: 2019-10-08
  • Updated: 2020-04-03
  • Resolved: 2019-10-15
Related Reports
CSR :  
Relates :  
Description
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"
Comments
There isn't any method that parses the output of this method.
16-10-2019

Is there any method that is expected to directly consume and parse this toString output? If so, it would be helpful if it were updated at the same time to recognize the new format. Please consider a release note is warranted for this change. Moving to Approved.
15-10-2019