--- old/src/java.base/share/classes/jdk/internal/loader/URLClassPath.java 2018-09-10 14:12:20.543490752 -0400 +++ new/src/java.base/share/classes/jdk/internal/loader/URLClassPath.java 2018-09-10 14:12:19.951490752 -0400 @@ -48,7 +48,6 @@ import java.security.cert.Certificate; import java.util.ArrayDeque; import java.util.ArrayList; -import java.util.Arrays; import java.util.Collections; import java.util.Enumeration; import java.util.HashMap; @@ -56,6 +55,7 @@ import java.util.LinkedList; import java.util.List; import java.util.NoSuchElementException; +import java.util.Objects; import java.util.Properties; import java.util.Set; import java.util.StringTokenizer; @@ -70,6 +70,7 @@ import jdk.internal.misc.JavaNetURLAccess; import jdk.internal.misc.JavaUtilZipFileAccess; import jdk.internal.misc.SharedSecrets; +import jdk.internal.util.PathParser; import jdk.internal.util.jar.InvalidJarIndexError; import jdk.internal.util.jar.JarIndex; import sun.net.util.URLUtil; @@ -101,7 +102,7 @@ } /* The original search path of URLs. */ - private final ArrayList path; + private final List path; /* The deque of unopened URLs */ private final ArrayDeque unopenedUrls; @@ -164,6 +165,8 @@ /** * Constructs a URLClassPath from a class path string. + * Empty path strings are later used to open a directory that defaults + * to the current directory. * * @param cp the class path string * @param skipEmptyElements indicates if empty elements are ignored or @@ -172,29 +175,21 @@ * @apiNote Used to create the application class path. */ URLClassPath(String cp, boolean skipEmptyElements) { - ArrayList path = new ArrayList<>(); - if (cp != null) { - // map each element of class path to a file URL - int off = 0, next; - do { - next = cp.indexOf(File.pathSeparator, off); - String element = (next == -1) - ? cp.substring(off) - : cp.substring(off, next); - if (element.length() > 0 || !skipEmptyElements) { - URL url = toFileURL(element); - if (url != null) path.add(url); - } - off = next + 1; - } while (next != -1); - } + String[] strings = PathParser + .parsePath(Objects.requireNonNullElse(cp, ""), + skipEmptyElements ? null : ""); + int size = strings.length; + ArrayList path = new ArrayList<>(size); + ArrayDeque unopenedUrls = new ArrayDeque<>(size); // can't use ArrayDeque#addAll or new ArrayDeque(Collection); // it's too early in the bootstrap to trigger use of lambdas - int size = path.size(); - ArrayDeque unopenedUrls = new ArrayDeque<>(size); - for (int i = 0; i < size; i++) - unopenedUrls.add(path.get(i)); + // Add a URL for each path element to the paths and the unopenedUrls. + for (String s : strings) { + URL url = toFileURL(s); + path.add(url); + unopenedUrls.add(url); + } this.unopenedUrls = unopenedUrls; this.path = path;