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

Add InetAddress methods for parsing IP address literals



    • CSR
    • Resolution: Approved
    • 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



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


      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.


      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.


      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.


        Issue Links



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