8157716: jdk.internal.loader.ClassLoaders.addURLToUCP() should return converted real path URL

Rename jdk.internal.loader.ClassLoaders.addURLToUCP() to toFileURL(), which returns the converted URL.

Reviewed-by: martin, mchung
This commit is contained in:
Alan Bateman 2016-05-25 17:29:47 -04:00 committed by Jiangli Zhou
parent e3aacefb01
commit 10f79f95df

View File

@ -237,24 +237,29 @@ public class ClassLoaders {
int off = 0; int off = 0;
int next; int next;
while ((next = cp.indexOf(File.pathSeparator, off)) != -1) { while ((next = cp.indexOf(File.pathSeparator, off)) != -1) {
addURLToUCP(cp.substring(off, next), ucp); URL url = toFileURL(cp.substring(off, next));
if (url != null)
ucp.addURL(url);
off = next + 1; off = next + 1;
} }
// remaining // remaining
addURLToUCP(cp.substring(off), ucp); URL url = toFileURL(cp.substring(off));
if (url != null)
ucp.addURL(url);
} }
/** /**
* Attempts to convert to the given string to a file URL and adds it * Attempts to convert the given string to a file URL.
* to the given URLClassPath. *
* @apiNote This is called by the VM
*/ */
private static void addURLToUCP(String s, URLClassPath ucp) { private static URL toFileURL(String s) {
try { try {
URL url = Paths.get(s).toRealPath().toUri().toURL(); return Paths.get(s).toRealPath().toUri().toURL();
ucp.addURL(url);
} catch (InvalidPathException | IOException ignore) { } catch (InvalidPathException | IOException ignore) {
// malformed path string or class path element does not exist // malformed path string or class path element does not exist
return null;
} }
} }