changeset 13569:a22556a5cd77

8148626: URI.toURL needs to use protocol Handler to parse file URIs Summary: Back out the parts of 8147462 that attempted to optimize file URI to URL conversions Reviewed-by: darcy, chegar
author redestad
date Sun, 31 Jan 2016 22:30:35 +0100
parents 3bce90b8839e
children 9e42f8c9d0ed
files src/java.base/share/classes/java/net/URL.java
diffstat 1 files changed, 10 insertions(+), 8 deletions(-) [+]
line wrap: on
line diff
--- a/src/java.base/share/classes/java/net/URL.java	Fri Jan 29 17:03:17 2016 -0800
+++ b/src/java.base/share/classes/java/net/URL.java	Sun Jan 31 22:30:35 2016 +0100
@@ -669,13 +669,15 @@
             throw new IllegalArgumentException("URI is not absolute");
         }
         String protocol = uri.getScheme();
-        if (!uri.isOpaque() && uri.getRawFragment() == null &&
-                !isOverrideable(protocol)) {
-            // non-opaque URIs will have already validated the components,
-            // so using the component-based URL constructor here is safe.
-            //
-            // All URL constructors will properly check if the scheme
-            // maps to a valid protocol handler
+
+        // In general we need to go via Handler.parseURL, but for the jrt
+        // protocol we enforce that the Handler is not overrideable and can
+        // optimize URI to URL conversion.
+        //
+        // Case-sensitive comparison for performance; malformed protocols will
+        // be handled correctly by the slow path.
+        if (protocol.equals("jrt") && !uri.isOpaque()
+                && uri.getRawFragment() == null) {
 
             String query = uri.getRawQuery();
             String path = uri.getRawPath();
@@ -689,7 +691,7 @@
 
             int port = uri.getPort();
 
-            return new URL(protocol, host, port, file, null);
+            return new URL("jrt", host, port, file, null);
         } else {
             return new URL((URL)null, uri.toString(), null);
         }