changeset 53150:dee9426ef417

8215990: Avoid using reflection to create common default URLStreamHandlers Reviewed-by: alanb
author redestad
date Wed, 02 Jan 2019 19:06:16 +0100
parents a22e41395bfa
children 3d0f6ef91216
files src/java.base/share/classes/java/net/URL.java
diffstat 1 files changed, 12 insertions(+), 6 deletions(-) [+]
line wrap: on
line diff
--- a/src/java.base/share/classes/java/net/URL.java	Wed Jan 02 13:06:04 2019 -0500
+++ b/src/java.base/share/classes/java/net/URL.java	Wed Jan 02 19:06:16 2019 +0100
@@ -1220,16 +1220,22 @@
     private static final URLStreamHandlerFactory defaultFactory = new DefaultFactory();
 
     private static class DefaultFactory implements URLStreamHandlerFactory {
-        private static String PREFIX = "sun.net.www.protocol";
+        private static String PREFIX = "sun.net.www.protocol.";
 
         public URLStreamHandler createURLStreamHandler(String protocol) {
-            String name = PREFIX + "." + protocol + ".Handler";
+            // Avoid using reflection during bootstrap
+            switch (protocol) {
+                case "file":
+                    return new sun.net.www.protocol.file.Handler();
+                case "jar":
+                    return new sun.net.www.protocol.jar.Handler();
+                case "jrt":
+                    return new sun.net.www.protocol.jrt.Handler();
+            }
+            String name = PREFIX + protocol + ".Handler";
             try {
-                @SuppressWarnings("deprecation")
-                Object o = Class.forName(name).newInstance();
+                Object o = Class.forName(name).getDeclaredConstructor().newInstance();
                 return (URLStreamHandler)o;
-            } catch (ClassNotFoundException x) {
-                // ignore
             } catch (Exception e) {
                 // For compatibility, all Exceptions are ignored.
                 // any number of exceptions can get thrown here