8148626: URI.toURL needs to use protocol Handler to parse file URIs

Back out the parts of 8147462 that attempted to optimize file URI to URL conversions

Reviewed-by: darcy, chegar
This commit is contained in:
Claes Redestad 2016-01-31 22:30:35 +01:00
parent 1685766e91
commit 9102b6eb21

View File

@ -669,13 +669,15 @@ public final class URL implements java.io.Serializable {
throw new IllegalArgumentException("URI is not absolute"); throw new IllegalArgumentException("URI is not absolute");
} }
String protocol = uri.getScheme(); String protocol = uri.getScheme();
if (!uri.isOpaque() && uri.getRawFragment() == null &&
!isOverrideable(protocol)) { // In general we need to go via Handler.parseURL, but for the jrt
// non-opaque URIs will have already validated the components, // protocol we enforce that the Handler is not overrideable and can
// so using the component-based URL constructor here is safe. // optimize URI to URL conversion.
// //
// All URL constructors will properly check if the scheme // Case-sensitive comparison for performance; malformed protocols will
// maps to a valid protocol handler // be handled correctly by the slow path.
if (protocol.equals("jrt") && !uri.isOpaque()
&& uri.getRawFragment() == null) {
String query = uri.getRawQuery(); String query = uri.getRawQuery();
String path = uri.getRawPath(); String path = uri.getRawPath();
@ -689,7 +691,7 @@ public final class URL implements java.io.Serializable {
int port = uri.getPort(); int port = uri.getPort();
return new URL(protocol, host, port, file, null); return new URL("jrt", host, port, file, null);
} else { } else {
return new URL((URL)null, uri.toString(), null); return new URL((URL)null, uri.toString(), null);
} }