Skip to content

Commit 2ca4ff8

Browse files
AlekseiEfimovChrisHegartydfuchAlan Bateman
committed
8244202: Implementation of JEP 418: Internet-Address Resolution SPI
Co-authored-by: Chris Hegarty <chegar@openjdk.org> Co-authored-by: Daniel Fuchs <dfuchs@openjdk.org> Co-authored-by: Alan Bateman <alanb@openjdk.org> Reviewed-by: dfuchs, alanb, michaelm, chegar
1 parent c29cab8 commit 2ca4ff8

File tree

56 files changed

+2986
-293
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

56 files changed

+2986
-293
lines changed

src/java.base/share/classes/java/lang/RuntimePermission.java

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 1997, 2020, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 1997, 2021, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -378,6 +378,16 @@
378378
* {@linkplain ModuleFinder#ofSystem system modules} in the runtime image.</td>
379379
* </tr>
380380
*
381+
* <tr>
382+
* <th scope="row">inetAddressResolverProvider</th>
383+
* <td>This {@code RuntimePermission} is required to be granted to
384+
* classes which subclass and implement {@code java.net.spi.InetAddressResolverProvider}.
385+
* The permission is checked during invocation of the abstract base class constructor.
386+
* This permission ensures trust in classes which provide resolvers used by
387+
* {@link java.net.InetAddress} hostname and address resolution methods.</td>
388+
* <td>See {@link java.net.spi.InetAddressResolverProvider} for more information.</td>
389+
* </tr>
390+
*
381391
* </tbody>
382392
* </table>
383393
*

src/java.base/share/classes/java/net/Inet4AddressImpl.java

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,9 @@
2424
*/
2525
package java.net;
2626
import java.io.IOException;
27+
import java.net.spi.InetAddressResolver.LookupPolicy;
28+
29+
import static java.net.spi.InetAddressResolver.LookupPolicy.IPV4;
2730

2831
/*
2932
* Package private implementation of InetAddressImpl for IPv4.
@@ -32,8 +35,14 @@
3235
*/
3336
final class Inet4AddressImpl implements InetAddressImpl {
3437
public native String getLocalHostName() throws UnknownHostException;
35-
public native InetAddress[]
36-
lookupAllHostAddr(String hostname) throws UnknownHostException;
38+
public InetAddress[] lookupAllHostAddr(String hostname, LookupPolicy lookupPolicy)
39+
throws UnknownHostException {
40+
if ((lookupPolicy.characteristics() & IPV4) == 0) {
41+
throw new UnknownHostException(hostname);
42+
}
43+
return lookupAllHostAddr(hostname);
44+
}
45+
private native InetAddress[] lookupAllHostAddr(String hostname) throws UnknownHostException;
3746
public native String getHostByAddr(byte[] addr) throws UnknownHostException;
3847
private native boolean isReachable0(byte[] addr, int timeout, byte[] ifaddr, int ttl) throws IOException;
3948

src/java.base/share/classes/java/net/Inet6AddressImpl.java

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,9 @@
2525
package java.net;
2626

2727
import java.io.IOException;
28+
import java.net.spi.InetAddressResolver.LookupPolicy;
2829

29-
import static java.net.InetAddress.IPv6;
30-
import static java.net.InetAddress.PREFER_IPV6_VALUE;
31-
import static java.net.InetAddress.PREFER_SYSTEM_VALUE;
30+
import static java.net.InetAddress.PLATFORM_LOOKUP_POLICY;
3231

3332
/*
3433
* Package private implementation of InetAddressImpl for dual
@@ -48,8 +47,13 @@ final class Inet6AddressImpl implements InetAddressImpl {
4847

4948
public native String getLocalHostName() throws UnknownHostException;
5049

51-
public native InetAddress[] lookupAllHostAddr(String hostname)
52-
throws UnknownHostException;
50+
public InetAddress[] lookupAllHostAddr(String hostname, LookupPolicy lookupPolicy)
51+
throws UnknownHostException {
52+
return lookupAllHostAddr(hostname, lookupPolicy.characteristics());
53+
}
54+
55+
private native InetAddress[] lookupAllHostAddr(String hostname, int characteristics)
56+
throws UnknownHostException;
5357

5458
public native String getHostByAddr(byte[] addr) throws UnknownHostException;
5559

@@ -96,8 +100,9 @@ public boolean isReachable(InetAddress addr, int timeout,
96100

97101
public synchronized InetAddress anyLocalAddress() {
98102
if (anyLocalAddress == null) {
99-
if (InetAddress.preferIPv6Address == PREFER_IPV6_VALUE ||
100-
InetAddress.preferIPv6Address == PREFER_SYSTEM_VALUE) {
103+
int flags = PLATFORM_LOOKUP_POLICY.characteristics();
104+
if (InetAddress.ipv6AddressesFirst(flags) ||
105+
InetAddress.systemAddressesOrder(flags)) {
101106
anyLocalAddress = new Inet6Address();
102107
anyLocalAddress.holder().hostName = "::";
103108
} else {
@@ -109,9 +114,9 @@ public synchronized InetAddress anyLocalAddress() {
109114

110115
public synchronized InetAddress loopbackAddress() {
111116
if (loopbackAddress == null) {
112-
boolean preferIPv6Address =
113-
InetAddress.preferIPv6Address == PREFER_IPV6_VALUE ||
114-
InetAddress.preferIPv6Address == PREFER_SYSTEM_VALUE;
117+
int flags = PLATFORM_LOOKUP_POLICY.characteristics();
118+
boolean preferIPv6Address = InetAddress.ipv6AddressesFirst(flags) ||
119+
InetAddress.systemAddressesOrder(flags);
115120

116121
for (int i = 0; i < 2; i++) {
117122
InetAddress address;

0 commit comments

Comments
 (0)