Skip to content

Commit 929b6a3

Browse files
committedMar 24, 2022
8282917: Remove InetAddressImplFactory from InetAddress
Reviewed-by: dfuchs, jpai
1 parent 14c20bc commit 929b6a3

File tree

4 files changed

+17
-107
lines changed

4 files changed

+17
-107
lines changed
 

‎src/java.base/share/classes/java/net/InetAddress.java

+5-14
Original file line numberDiff line numberDiff line change
@@ -412,6 +412,9 @@ static boolean ipv6AddressesFirst(int lookupCharacteristics) {
412412
// Native method to check if IPv4 is available
413413
private static native boolean isIPv4Available();
414414

415+
// Native method to check if IPv6 is available
416+
private static native boolean isIPv6Supported();
417+
415418
/**
416419
* The {@code RuntimePermission("inetAddressResolverProvider")} is
417420
* necessary to subclass and instantiate the {@code InetAddressResolverProvider}
@@ -1270,7 +1273,8 @@ private String extractHostAddr(String hostEntry, String host) {
12701273

12711274
static {
12721275
// create the impl
1273-
impl = InetAddressImplFactory.create();
1276+
impl = isIPv6Supported() ?
1277+
new Inet6AddressImpl() : new Inet4AddressImpl();
12741278

12751279
// impl must be initialized before calling this method
12761280
PLATFORM_LOOKUP_POLICY = initializePlatformLookupPolicy();
@@ -1826,16 +1830,3 @@ private void writeObject (ObjectOutputStream s) throws IOException {
18261830
s.writeFields();
18271831
}
18281832
}
1829-
1830-
/*
1831-
* Simple factory to create the impl
1832-
*/
1833-
class InetAddressImplFactory {
1834-
1835-
static InetAddressImpl create() {
1836-
return isIPv6Supported() ?
1837-
new Inet6AddressImpl() : new Inet4AddressImpl();
1838-
}
1839-
1840-
static native boolean isIPv6Supported();
1841-
}

‎src/java.base/share/native/libnet/InetAddress.c

+12-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 1997, 2021, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 1997, 2022, 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
@@ -76,8 +76,19 @@ Java_java_net_InetAddress_init(JNIEnv *env, jclass cls) {
7676
/*
7777
* Class: java_net_InetAddress
7878
* Method: isIPv4Available
79+
* Signature: ()Z
7980
*/
8081
JNIEXPORT jboolean JNICALL
8182
Java_java_net_InetAddress_isIPv4Available(JNIEnv *env, jclass clazz) {
8283
return ipv4_available();
8384
}
85+
86+
/*
87+
* Class: java_net_InetAddress
88+
* Method: isIPv6Supported
89+
* Signature: ()Z
90+
*/
91+
JNIEXPORT jboolean JNICALL
92+
Java_java_net_InetAddress_isIPv6Supported(JNIEnv *env, jclass clazz) {
93+
return ipv6_available();
94+
}

‎src/java.base/unix/native/libnet/InetAddressImplFactory.c

-46
This file was deleted.

‎src/java.base/windows/native/libnet/InetAddressImplFactory.c

-46
This file was deleted.

1 commit comments

Comments
 (1)

openjdk-notifier[bot] commented on Mar 24, 2022

@openjdk-notifier[bot]
Please sign in to comment.