From 6668b3c40df19c8b05acdead7dd46587185cf41a Mon Sep 17 00:00:00 2001 From: Eric Anderson Date: Tue, 14 Apr 2015 10:54:25 -0700 Subject: [PATCH] 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. --- .../java/io/netty/handler/ssl/JdkAlpnSslEngine.java | 10 ++-------- .../java/io/netty/handler/ssl/JdkNpnSslEngine.java | 10 ++-------- 2 files changed, 4 insertions(+), 16 deletions(-) diff --git a/handler/src/main/java/io/netty/handler/ssl/JdkAlpnSslEngine.java b/handler/src/main/java/io/netty/handler/ssl/JdkAlpnSslEngine.java index 012b1676bf..6cfacb8b80 100644 --- a/handler/src/main/java/io/netty/handler/ssl/JdkAlpnSslEngine.java +++ b/handler/src/main/java/io/netty/handler/ssl/JdkAlpnSslEngine.java @@ -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. diff --git a/handler/src/main/java/io/netty/handler/ssl/JdkNpnSslEngine.java b/handler/src/main/java/io/netty/handler/ssl/JdkNpnSslEngine.java index 43d5bb584f..422727aa6e 100644 --- a/handler/src/main/java/io/netty/handler/ssl/JdkNpnSslEngine.java +++ b/handler/src/main/java/io/netty/handler/ssl/JdkNpnSslEngine.java @@ -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.