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:
java.net.Inet4Address.ofLiteral
- parses the given string as an IPv4 address literaljava.net.Inet6Address.ofLiteral
- parses the given string as an IPv6 address literaljava.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.
- csr of
-
JDK-8272215 Add InetAddress methods for parsing IP address literals
-
- Resolved
-
- relates to
-
JDK-8319450 New methods java.net.InetXAddress.ofLiteral() miss @since tag
-
- Closed
-