Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8232002

InetSocketAddress::toString not friendly to IPv6 literal addresses

    XMLWordPrintable

    Details

    • Type: CSR
    • Status: Closed
    • Priority: P3
    • Resolution: Approved
    • Fix Version/s: 14
    • Component/s: core-libs
    • Labels:
      None
    • Subcomponent:
    • Compatibility Kind:
      behavioral
    • Compatibility Risk:
      low
    • Compatibility Risk Description:
      The compatibility risk is low as this proposal changes the implementation of the InetSocketAddress::toString method only, but there is still the risk that some application might be trying to parse the returned string.
    • Interface Kind:
      Java API
    • Scope:
      SE

      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. Additionally, the format currently specified for unresolved addresses does not obey the above formatting, which could lead to further confusion.

      Solution

      In InetSocketAddress::toString:
      1. enclose IPv6 literals in brackets in the manner of RFC 2732.
      2. replace the IP literal with the token <unresolved> if InetSocketAddress is unresolved.

      Examples:

      InetSocketAddress.createUnresolved("foo", 80).toString() returns
      before: foo:80
      after: foo/<unresolved>:80

      new InetSocketAddress("::1", 80).toString() returns
      before: /0:0:0:0:0:0:0:1:80
      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/

        Attachments

          Issue Links

            Activity

              People

              Assignee:
              jboes Julia Boes
              Reporter:
              alanb Alan Bateman
              Reviewed By:
              Chris Hegarty, Daniel Fuchs
              Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

                Dates

                Created:
                Updated:
                Resolved: