JEP 418: Internet-Address Resolution SPI

OwnerAleksej Efimov
TypeFeature
ScopeSE
StatusCandidate
Componentcore-libs / java.net
Discussionnet dash dev at openjdk dot java dot net
DurationS
Reviewed byAlan Bateman, Brian Goetz, Chris Hegarty, Daniel Fuchs
Created2021/03/16 16:43
Updated2021/09/20 10:14
Issue8263693

Summary

Define a service-provider interface (SPI) for host name and address resolution, so that java.net.InetAddress can make use of resolvers other than the platform's built-in resolver.

Non-Goals

Motivation

The java.net.InetAddress API resolves host names to Internet Protocol (IP) addresses, and vice versa. The API currently uses the operating system's native resolver, which is typically configured to use a combination of a local hosts file and the Domain Name System (DNS).

Motivations for defining a service-provider interface for name and address resolution include:

Description

The InetAddress API defines multiple methods for lookup operations:

By default, InetAddress uses the operating system's native resolver to perform lookups. The result of that lookup, whether positive or negative, may be cached in order to avoid further lookups of the same host.

Service-provider interface

The InetAddress API will use a service loader to locate a resolver provider. If no provider is found, the built-in implementation will be used as before.

The new classes in the java.net.spi package are:

Alternatives

Without an SPI such as the one proposed here, applications will have to continue to use the workarounds available today.

Testing

We will develop new tests for the resolver SPI.

We will develop proof-of-concept resolver providers to demonstrate and verify that the SPI can be used to develop and deploy alternative implementations that are used in preference to the JDK's built-in implementation. We will make at least one of these providers available to seed development of more complete implementations.