8274227: Remove "impl.prefix" jdk system property usage from InetAddress
Reviewed-by: alanb, dfuchs
This commit is contained in:
parent
292d7bb1d5
commit
cc14c6f076
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2002, 2013, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2002, 2021, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
@ -30,7 +30,7 @@ import java.io.IOException;
|
||||
*
|
||||
* @since 1.4
|
||||
*/
|
||||
class Inet4AddressImpl implements InetAddressImpl {
|
||||
final class Inet4AddressImpl implements InetAddressImpl {
|
||||
public native String getLocalHostName() throws UnknownHostException;
|
||||
public native InetAddress[]
|
||||
lookupAllHostAddr(String hostname) throws UnknownHostException;
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2002, 2019, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2002, 2021, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
@ -44,7 +44,7 @@ import static java.net.InetAddress.PREFER_SYSTEM_VALUE;
|
||||
*
|
||||
* @since 1.4
|
||||
*/
|
||||
class Inet6AddressImpl implements InetAddressImpl {
|
||||
final class Inet6AddressImpl implements InetAddressImpl {
|
||||
|
||||
public native String getLocalHostName() throws UnknownHostException;
|
||||
|
||||
|
@ -1668,51 +1668,6 @@ public class InetAddress implements java.io.Serializable {
|
||||
return impl.anyLocalAddress();
|
||||
}
|
||||
|
||||
/*
|
||||
* Load and instantiate an underlying impl class
|
||||
*/
|
||||
static InetAddressImpl loadImpl(String implName) {
|
||||
Object impl = null;
|
||||
|
||||
/*
|
||||
* Property "impl.prefix" will be prepended to the classname
|
||||
* of the implementation object we instantiate, to which we
|
||||
* delegate the real work (like native methods). This
|
||||
* property can vary across implementations of the java.
|
||||
* classes. The default is an empty String "".
|
||||
*/
|
||||
String prefix = GetPropertyAction.privilegedGetProperty("impl.prefix", "");
|
||||
try {
|
||||
@SuppressWarnings("deprecation")
|
||||
Object tmp = Class.forName("java.net." + prefix + implName).newInstance();
|
||||
impl = tmp;
|
||||
} catch (ClassNotFoundException e) {
|
||||
System.err.println("Class not found: java.net." + prefix +
|
||||
implName + ":\ncheck impl.prefix property " +
|
||||
"in your properties file.");
|
||||
} catch (InstantiationException e) {
|
||||
System.err.println("Could not instantiate: java.net." + prefix +
|
||||
implName + ":\ncheck impl.prefix property " +
|
||||
"in your properties file.");
|
||||
} catch (IllegalAccessException e) {
|
||||
System.err.println("Cannot access class: java.net." + prefix +
|
||||
implName + ":\ncheck impl.prefix property " +
|
||||
"in your properties file.");
|
||||
}
|
||||
|
||||
if (impl == null) {
|
||||
try {
|
||||
@SuppressWarnings("deprecation")
|
||||
Object tmp = Class.forName(implName).newInstance();
|
||||
impl = tmp;
|
||||
} catch (Exception e) {
|
||||
throw new Error("System property impl.prefix incorrect");
|
||||
}
|
||||
}
|
||||
|
||||
return (InetAddressImpl) impl;
|
||||
}
|
||||
|
||||
/**
|
||||
* Initializes an empty InetAddress.
|
||||
*/
|
||||
@ -1793,8 +1748,8 @@ public class InetAddress implements java.io.Serializable {
|
||||
class InetAddressImplFactory {
|
||||
|
||||
static InetAddressImpl create() {
|
||||
return InetAddress.loadImpl(isIPv6Supported() ?
|
||||
"Inet6AddressImpl" : "Inet4AddressImpl");
|
||||
return isIPv6Supported() ?
|
||||
new Inet6AddressImpl() : new Inet4AddressImpl();
|
||||
}
|
||||
|
||||
static native boolean isIPv6Supported();
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2002, 2005, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2002, 2021, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
@ -34,7 +34,7 @@ import java.io.IOException;
|
||||
*
|
||||
* @since 1.4
|
||||
*/
|
||||
interface InetAddressImpl {
|
||||
sealed interface InetAddressImpl permits Inet4AddressImpl, Inet6AddressImpl {
|
||||
|
||||
String getLocalHostName() throws UnknownHostException;
|
||||
InetAddress[]
|
||||
|
Loading…
x
Reference in New Issue
Block a user