The "null" ClassLoader is the bootstrap ClassLoader

Motivation:
Class.forName() documents that null will use bootstrap loader:
http://docs.oracle.com/javase/8/docs/api/java/lang/Class.html#forName-java.lang.String-boolean-java.lang.ClassLoader-

But the link between "null" and bootstrap loader is even more explicit
in ClassLoader's documentation:
http://docs.oracle.com/javase/8/docs/api/java/lang/ClassLoader.html#getParent--

The current code is trying to use the bootstrap loader but seems to have
not been aware of the meaning of null.

Modifications:
Use "null" as the class loader when we want to load classes in the
bootstrap loader.

Result:
More reliable ALPN/NPN loading and simpler code.
This commit is contained in:
Eric Anderson 2015-04-14 10:54:25 -07:00 committed by Norman Maurer
parent 854859ba69
commit 4e70523edd
2 changed files with 4 additions and 16 deletions

View File

@ -44,14 +44,8 @@ final class JdkAlpnSslEngine extends JdkSslEngine {
}
try {
// Try to get the bootstrap class loader.
ClassLoader bootloader = ClassLoader.getSystemClassLoader().getParent();
if (bootloader == null) {
// If failed, use the system class loader,
// although it's not perfect to tell if APLN extension has been loaded.
bootloader = ClassLoader.getSystemClassLoader();
}
Class.forName("sun.security.ssl.ALPNExtension", true, bootloader);
// Always use bootstrap class loader.
Class.forName("sun.security.ssl.ALPNExtension", true, null);
available = true;
} catch (Exception ignore) {
// alpn-boot was not loaded.

View File

@ -44,14 +44,8 @@ final class JdkNpnSslEngine extends JdkSslEngine {
return;
}
try {
// Try to get the bootstrap class loader.
ClassLoader bootloader = ClassLoader.getSystemClassLoader().getParent();
if (bootloader == null) {
// If failed, use the system class loader,
// although it's not perfect to tell if NPN extension has been loaded.
bootloader = ClassLoader.getSystemClassLoader();
}
Class.forName("sun.security.ssl.NextProtoNegoExtension", true, bootloader);
// Always use bootstrap class loader.
Class.forName("sun.security.ssl.NextProtoNegoExtension", true, null);
available = true;
} catch (Exception ignore) {
// npn-boot was not loaded.