Skip to content

Commit cc14c6f

Browse files
committed
8274227: Remove "impl.prefix" jdk system property usage from InetAddress
Reviewed-by: alanb, dfuchs
1 parent 292d7bb commit cc14c6f

File tree

4 files changed

+8
-53
lines changed

4 files changed

+8
-53
lines changed

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2002, 2013, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2002, 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
@@ -30,7 +30,7 @@
3030
*
3131
* @since 1.4
3232
*/
33-
class Inet4AddressImpl implements InetAddressImpl {
33+
final class Inet4AddressImpl implements InetAddressImpl {
3434
public native String getLocalHostName() throws UnknownHostException;
3535
public native InetAddress[]
3636
lookupAllHostAddr(String hostname) throws UnknownHostException;

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2002, 2019, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2002, 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
@@ -44,7 +44,7 @@
4444
*
4545
* @since 1.4
4646
*/
47-
class Inet6AddressImpl implements InetAddressImpl {
47+
final class Inet6AddressImpl implements InetAddressImpl {
4848

4949
public native String getLocalHostName() throws UnknownHostException;
5050

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

Lines changed: 2 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -1668,51 +1668,6 @@ static InetAddress anyLocalAddress() {
16681668
return impl.anyLocalAddress();
16691669
}
16701670

1671-
/*
1672-
* Load and instantiate an underlying impl class
1673-
*/
1674-
static InetAddressImpl loadImpl(String implName) {
1675-
Object impl = null;
1676-
1677-
/*
1678-
* Property "impl.prefix" will be prepended to the classname
1679-
* of the implementation object we instantiate, to which we
1680-
* delegate the real work (like native methods). This
1681-
* property can vary across implementations of the java.
1682-
* classes. The default is an empty String "".
1683-
*/
1684-
String prefix = GetPropertyAction.privilegedGetProperty("impl.prefix", "");
1685-
try {
1686-
@SuppressWarnings("deprecation")
1687-
Object tmp = Class.forName("java.net." + prefix + implName).newInstance();
1688-
impl = tmp;
1689-
} catch (ClassNotFoundException e) {
1690-
System.err.println("Class not found: java.net." + prefix +
1691-
implName + ":\ncheck impl.prefix property " +
1692-
"in your properties file.");
1693-
} catch (InstantiationException e) {
1694-
System.err.println("Could not instantiate: java.net." + prefix +
1695-
implName + ":\ncheck impl.prefix property " +
1696-
"in your properties file.");
1697-
} catch (IllegalAccessException e) {
1698-
System.err.println("Cannot access class: java.net." + prefix +
1699-
implName + ":\ncheck impl.prefix property " +
1700-
"in your properties file.");
1701-
}
1702-
1703-
if (impl == null) {
1704-
try {
1705-
@SuppressWarnings("deprecation")
1706-
Object tmp = Class.forName(implName).newInstance();
1707-
impl = tmp;
1708-
} catch (Exception e) {
1709-
throw new Error("System property impl.prefix incorrect");
1710-
}
1711-
}
1712-
1713-
return (InetAddressImpl) impl;
1714-
}
1715-
17161671
/**
17171672
* Initializes an empty InetAddress.
17181673
*/
@@ -1793,8 +1748,8 @@ private void writeObject (ObjectOutputStream s) throws
17931748
class InetAddressImplFactory {
17941749

17951750
static InetAddressImpl create() {
1796-
return InetAddress.loadImpl(isIPv6Supported() ?
1797-
"Inet6AddressImpl" : "Inet4AddressImpl");
1751+
return isIPv6Supported() ?
1752+
new Inet6AddressImpl() : new Inet4AddressImpl();
17981753
}
17991754

18001755
static native boolean isIPv6Supported();

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2002, 2005, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2002, 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
@@ -34,7 +34,7 @@
3434
*
3535
* @since 1.4
3636
*/
37-
interface InetAddressImpl {
37+
sealed interface InetAddressImpl permits Inet4AddressImpl, Inet6AddressImpl {
3838

3939
String getLocalHostName() throws UnknownHostException;
4040
InetAddress[]

0 commit comments

Comments
 (0)