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

Add InetAddress methods for parsing IP address literals

    XMLWordPrintable

Details

    • b22
    • generic
    • generic

    Description

      A DESCRIPTION OF THE PROBLEM :
      The class java.net.InetAddress only provides the method InetAddress.getByName(String) for parsing IP address literals. However, if (for example due to a bug in an application) the address is malformed InetAddress might perform a host lookup which can be undesired.

      See related StackOverflow questions and comments:
      - https://stackoverflow.com/questions/5571744/java-convert-a-string-representing-an-ip-to-inetaddress
      - https://stackoverflow.com/questions/2309049/is-there-an-easy-way-to-convert-string-to-inetaddress-in-java

      The need for such functionality has also caused Guava to have the InetAddresses class, see
      https://guava.dev/releases/snapshot-jre/api/docs/com/google/common/net/InetAddresses.html

      It would therefore be good to have the following methods:
      - for parsing an IPv4 literal (this method could be part of Inet4Address)
      - for parsing an IPv6 literal (this method could be part of Inet6Address)
      - for parsing an IP address literal which is either IPv4 or IPv6

      If a malformed IP address literal is provided, it might be good to either return null, or throw an exception, such as IllegalArgumentException.

      Note that the functionality for this already exists in sun.net.util.IPAddressUtil, it "merely" has to be exposed as part of a public API.


      Attachments

        Issue Links

          Activity

            People

              aefimov Aleksej Efimov
              webbuggrp Webbug Group
              Votes:
              0 Vote for this issue
              Watchers:
              5 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: