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

Add InetAddress methods for parsing IP address literals

XMLWordPrintable

    • Icon: CSR CSR
    • Resolution: Approved
    • Icon: P4 P4
    • 22
    • core-libs
    • None
    • binary
    • minimal
    • New API methods are only exposing IP address literals parsing functionality already available in internal classes and methods.
    • Java API
    • SE

      Summary

      Introduce a new API for parsing IPv4 and IPv6 address literals.

      Problem

      The java.net.InetAddress class only provides the InetAddress.getByName and the InetAddress.getAllByName methods for parsing IP address literals. However, these methods perform a host lookup if an address literal is supplied in a malformed textual representation of an IP address. Such behavior can be undesirable, and there is a need for methods that are capable of parsing IP address literals that throw an exception if a malformed IP literal is specified.

      Solution

      Add three static methods to parse IPv4, IPv6 and any IP literals respectively:

      1. java.net.Inet4Address.ofLiteral - parses the given string as an IPv4 address literal
      2. java.net.Inet6Address.ofLiteral - parses the given string as an IPv6 address literal
      3. java.net.InetAddress.ofLiteral - parses the given string as an IPv4 or an IPv6 address literal

      If an address literal supplied to one of these methods cannot represent a valid IP address an IllegalArgumentException is thrown.

      The documentation of java.net.InetAddress, java.net.Inet4Address, and java.net.Inet6Address classes also updated to clarify aspects of supported IP address textual representations.

      Specification

      New methods are added to java.net.InetAddress, java.net.Inet4Address, and java.net.Inet6Address.

      Relevant documentation of affected classes is changed to clarify supported textual representations of IPv4 and IPv6 addresses.

      The "IPv6 scoped address architecture" specification link mentioned in the java.net.Inet6Address class documentation was updated to point to the correct document. It is also added to the list of external specifications.

      All changes listed above can be viewed in the attached specdiff.zip file.

            aefimov Aleksej Efimov
            webbuggrp Webbug Group
            Daniel Fuchs, Michael McMahon
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Resolved: