8132705: Refactor SharedSecrets in sun.misc.JavaNetAccess

Factor out access for InetAddress

Reviewed-by: chegar, michaelm, alanb
This commit is contained in:
Roger Riggs 2015-07-30 14:16:58 -04:00
parent 46d78c85b4
commit a0824cf9ea
6 changed files with 56 additions and 13 deletions

@ -297,6 +297,13 @@ class InetAddress implements java.io.Serializable {
return null;
}
});
sun.misc.SharedSecrets.setJavaNetInetAddressAccess(
new sun.misc.JavaNetInetAddressAccess() {
public String getOriginalHostName(InetAddress ia) {
return ia.holder.getOriginalHostName();
}
}
);
init();
}

@ -774,10 +774,6 @@ public class URLClassLoader extends SecureClassLoader implements Closeable {
public URLClassPath getURLClassPath (URLClassLoader u) {
return u.ucp;
}
public String getOriginalHostName(InetAddress ia) {
return ia.holder.getOriginalHostName();
}
}
);
ClassLoader.registerAsParallelCapable();

@ -26,17 +26,10 @@
package sun.misc;
import java.net.URLClassLoader;
import java.net.InetAddress;
public interface JavaNetAccess {
/**
* return the URLClassPath belonging to the given loader
*/
URLClassPath getURLClassPath (URLClassLoader u);
/**
* Return the original application specified hostname of
* the given InetAddress object.
*/
String getOriginalHostName(InetAddress ia);
}

@ -0,0 +1,36 @@
/*
* Copyright (c) 2015, 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
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package sun.misc;
import java.net.InetAddress;
public interface JavaNetInetAddressAccess {
/**
* Return the original application specified hostname of
* the given InetAddress object.
*/
String getOriginalHostName(InetAddress ia);
}

@ -48,6 +48,7 @@ public class SharedSecrets {
private static JavaLangRefAccess javaLangRefAccess;
private static JavaIOAccess javaIOAccess;
private static JavaNetAccess javaNetAccess;
private static JavaNetInetAddressAccess javaNetInetAddressAccess;
private static JavaNetHttpCookieAccess javaNetHttpCookieAccess;
private static JavaNioAccess javaNioAccess;
private static JavaIOFileDescriptorAccess javaIOFileDescriptorAccess;
@ -92,9 +93,19 @@ public class SharedSecrets {
}
public static JavaNetAccess getJavaNetAccess() {
if (javaNetAccess == null)
unsafe.ensureClassInitialized(java.net.URLClassLoader.class);
return javaNetAccess;
}
public static void setJavaNetInetAddressAccess(JavaNetInetAddressAccess jna) {
javaNetInetAddressAccess = jna;
}
public static JavaNetInetAddressAccess getJavaNetInetAddressAccess() {
return javaNetInetAddressAccess;
}
public static void setJavaNetHttpCookieAccess(JavaNetHttpCookieAccess a) {
javaNetHttpCookieAccess = a;
}

@ -42,7 +42,7 @@ import javax.crypto.BadPaddingException;
import javax.net.ssl.*;
import sun.misc.ManagedLocalsThread;
import sun.misc.JavaNetAccess;
import sun.misc.JavaNetInetAddressAccess;
import sun.misc.SharedSecrets;
/**
@ -2096,7 +2096,7 @@ final public class SSLSocketImpl extends BaseSSLSocketImpl {
/*
* Get the original hostname via sun.misc.SharedSecrets.
*/
JavaNetAccess jna = SharedSecrets.getJavaNetAccess();
JavaNetInetAddressAccess jna = SharedSecrets.getJavaNetInetAddressAccess();
String originalHostname = jna.getOriginalHostName(inetAddress);
/*