< prev index next >
src/java.base/share/classes/java/net/URL.java
Print this page
rev 13564 : 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:
*** 667,683 ****
static URL fromURI(URI uri) throws MalformedURLException {
if (!uri.isAbsolute()) {
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
String query = uri.getRawQuery();
String path = uri.getRawPath();
String file = (query == null) ? path : path + "?" + query;
--- 667,685 ----
static URL fromURI(URI uri) throws MalformedURLException {
if (!uri.isAbsolute()) {
throw new IllegalArgumentException("URI is not absolute");
}
String protocol = uri.getScheme();
!
! // 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();
String file = (query == null) ? path : path + "?" + query;
*** 687,697 ****
host = "";
}
int port = uri.getPort();
! return new URL(protocol, host, port, file, null);
} else {
return new URL((URL)null, uri.toString(), null);
}
}
--- 689,699 ----
host = "";
}
int port = uri.getPort();
! return new URL("jrt", host, port, file, null);
} else {
return new URL((URL)null, uri.toString(), null);
}
}
< prev index next >