Skip to content

Commit

Permalink
8274227: Remove "impl.prefix" jdk system property usage from InetAddress
Browse files Browse the repository at this point in the history
Reviewed-by: alanb, dfuchs
  • Loading branch information
AlekseiEfimov committed Oct 1, 2021
1 parent 292d7bb commit cc14c6f
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 53 deletions.
4 changes: 2 additions & 2 deletions src/java.base/share/classes/java/net/Inet4AddressImpl.java
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -30,7 +30,7 @@
*
* @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;
Expand Down
4 changes: 2 additions & 2 deletions src/java.base/share/classes/java/net/Inet6AddressImpl.java
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -44,7 +44,7 @@
*
* @since 1.4
*/
class Inet6AddressImpl implements InetAddressImpl {
final class Inet6AddressImpl implements InetAddressImpl {

public native String getLocalHostName() throws UnknownHostException;

Expand Down
49 changes: 2 additions & 47 deletions src/java.base/share/classes/java/net/InetAddress.java
Original file line number Diff line number Diff line change
Expand Up @@ -1668,51 +1668,6 @@ static InetAddress anyLocalAddress() {
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.
*/
Expand Down Expand Up @@ -1793,8 +1748,8 @@ private void writeObject (ObjectOutputStream s) throws
class InetAddressImplFactory {

static InetAddressImpl create() {
return InetAddress.loadImpl(isIPv6Supported() ?
"Inet6AddressImpl" : "Inet4AddressImpl");
return isIPv6Supported() ?
new Inet6AddressImpl() : new Inet4AddressImpl();
}

static native boolean isIPv6Supported();
Expand Down
4 changes: 2 additions & 2 deletions src/java.base/share/classes/java/net/InetAddressImpl.java
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -34,7 +34,7 @@
*
* @since 1.4
*/
interface InetAddressImpl {
sealed interface InetAddressImpl permits Inet4AddressImpl, Inet6AddressImpl {

String getLocalHostName() throws UnknownHostException;
InetAddress[]
Expand Down

1 comment on commit cc14c6f

@openjdk-notifier
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.