diff --git a/src/java.base/share/classes/java/net/URLStreamHandler.java b/src/java.base/share/classes/java/net/URLStreamHandler.java index 6b30d3cb43a4b..ba7627401a2f4 100644 --- a/src/java.base/share/classes/java/net/URLStreamHandler.java +++ b/src/java.base/share/classes/java/net/URLStreamHandler.java @@ -26,13 +26,8 @@ package java.net; import java.io.IOException; -import java.io.InputStream; -import java.io.File; -import java.io.OutputStream; -import java.util.Hashtable; import java.util.Objects; import sun.net.util.IPAddressUtil; -import sun.net.www.ParseUtil; /** * The abstract class {@code URLStreamHandler} is the common @@ -158,13 +153,12 @@ protected void parseURL(URL u, String spec, int start, int limit) { queryOnly = queryStart == start; if ((queryStart != -1) && (queryStart < limit)) { query = spec.substring(queryStart+1, limit); - if (limit > queryStart) - limit = queryStart; + limit = queryStart; spec = spec.substring(0, queryStart); } } - int i = 0; + int i; // Parse the authority part if any boolean isUNCName = (start <= limit - 4) && (spec.charAt(start) == '/') && @@ -249,7 +243,7 @@ protected void parseURL(URL u, String spec, int start, int limit) { start = i; // If the authority is defined then the path is defined by the // spec only; See RFC 2396 Section 5.2.4. - if (authority != null && !authority.isEmpty()) + if (!authority.isEmpty()) path = ""; } @@ -259,26 +253,27 @@ protected void parseURL(URL u, String spec, int start, int limit) { // Parse the file path if any if (start < limit) { + String specStr = spec.substring(start, limit); if (spec.charAt(start) == '/') { - path = spec.substring(start, limit); + path = specStr; } else if (path != null && !path.isEmpty()) { isRelPath = true; int ind = path.lastIndexOf('/'); - String separator = ""; - if (ind == -1 && authority != null) - separator = "/"; - path = path.substring(0, ind + 1) + separator + - spec.substring(start, limit); - + if (ind == -1 && authority != null) { + path = "/".concat(specStr); + } else { + path = path.substring(0, ind + 1).concat(specStr); + } } else { - path = spec.substring(start, limit); - path = (authority != null) ? "/" + path : path; + path = (authority != null) ? "/".concat(specStr) : specStr; } } else if (queryOnly && path != null) { int ind = path.lastIndexOf('/'); - if (ind < 0) - ind = 0; - path = path.substring(0, ind) + "/"; + if (ind < 0) { + path = "/"; + } else { + path = path.substring(0, ind + 1); + } } if (path == null) path = ""; @@ -299,7 +294,7 @@ protected void parseURL(URL u, String spec, int start, int limit) { */ if (i > 0 && (limit = path.lastIndexOf('/', i - 1)) >= 0 && (path.indexOf("/../", limit) != 0)) { - path = path.substring(0, limit) + path.substring(i + 3); + path = path.substring(0, limit).concat(path.substring(i + 3)); i = 0; } else { i = i + 3;