8157716: jdk.internal.loader.ClassLoaders.addURLToUCP() should return converted real path URL.
authorjiangli
Wed, 25 May 2016 17:29:47 -0400
changeset 38793 7dba4e68157d
parent 38792 7ae552b6344f
child 38794 4e7b5866fd50
8157716: jdk.internal.loader.ClassLoaders.addURLToUCP() should return converted real path URL. Summary: Rename jdk.internal.loader.ClassLoaders.addURLToUCP() to toFileURL(), which returns the converted URL. Reviewed-by: martin, mchung Contributed-by: alan.bateman@oracle.com
jdk/src/java.base/share/classes/jdk/internal/loader/ClassLoaders.java
--- a/jdk/src/java.base/share/classes/jdk/internal/loader/ClassLoaders.java	Tue May 24 14:14:18 2016 +0300
+++ b/jdk/src/java.base/share/classes/jdk/internal/loader/ClassLoaders.java	Wed May 25 17:29:47 2016 -0400
@@ -237,24 +237,29 @@
         int off = 0;
         int next;
         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;
         }
 
         // 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
-     * to the given URLClassPath.
+     * Attempts to convert the given string to a file URL.
+     *
+     * @apiNote This is called by the VM
      */
-    private static void addURLToUCP(String s, URLClassPath ucp) {
+    private static URL toFileURL(String s) {
         try {
-            URL url = Paths.get(s).toRealPath().toUri().toURL();
-            ucp.addURL(url);
+            return Paths.get(s).toRealPath().toUri().toURL();
         } catch (InvalidPathException | IOException ignore) {
             // malformed path string or class path element does not exist
+            return null;
         }
     }