8152277: Move URLClassPath.pathToURLs(String) to RegistryImpl
authorchegar
Thu, 24 Mar 2016 11:59:07 +0000
changeset 36670 acf999f92006
parent 36669 17af8b44d311
child 36671 6650d41439b6
child 36674 7ab530dd6f10
8152277: Move URLClassPath.pathToURLs(String) to RegistryImpl Reviewed-by: alanb
jdk/src/java.base/share/classes/sun/misc/URLClassPath.java
jdk/src/java.rmi/share/classes/sun/rmi/registry/RegistryImpl.java
--- a/jdk/src/java.base/share/classes/sun/misc/URLClassPath.java	Thu Mar 24 11:56:47 2016 +0000
+++ b/jdk/src/java.base/share/classes/sun/misc/URLClassPath.java	Thu Mar 24 11:59:07 2016 +0000
@@ -401,36 +401,6 @@
         }
     }
 
-    /**
-     * Convert class path specification into an array of file URLs.
-     *
-     * The path of the file is encoded before conversion into URL
-     * form so that reserved characters can safely appear in the path.
-     */
-    public static URL[] pathToURLs(String path) {
-        StringTokenizer st = new StringTokenizer(path, File.pathSeparator);
-        URL[] urls = new URL[st.countTokens()];
-        int count = 0;
-        while (st.hasMoreTokens()) {
-            File f = new File(st.nextToken());
-            try {
-                f = new File(f.getCanonicalPath());
-            } catch (IOException x) {
-                // use the non-canonicalized filename
-            }
-            try {
-                urls[count++] = ParseUtil.fileToEncodedURL(f);
-            } catch (IOException x) { }
-        }
-
-        if (urls.length != count) {
-            URL[] tmp = new URL[count];
-            System.arraycopy(urls, 0, tmp, 0, count);
-            urls = tmp;
-        }
-        return urls;
-    }
-
     /*
      * Check whether the resource URL should be returned.
      * Return null on security check failure.
--- a/jdk/src/java.rmi/share/classes/sun/rmi/registry/RegistryImpl.java	Thu Mar 24 11:56:47 2016 +0000
+++ b/jdk/src/java.rmi/share/classes/sun/rmi/registry/RegistryImpl.java	Thu Mar 24 11:59:07 2016 +0000
@@ -25,10 +25,15 @@
 
 package sun.rmi.registry;
 
+import java.nio.file.Path;
+import java.nio.file.Paths;
+import java.util.ArrayList;
 import java.util.Enumeration;
 import java.util.Hashtable;
+import java.util.List;
 import java.util.MissingResourceException;
 import java.util.ResourceBundle;
+import java.io.File;
 import java.io.FilePermission;
 import java.io.IOException;
 import java.net.*;
@@ -333,6 +338,30 @@
     }
 
     /**
+     * Convert class path specification into an array of file URLs.
+     *
+     * The path of the file is converted to a URI then into URL
+     * form so that reserved characters can safely appear in the path.
+     */
+    private static URL[] pathToURLs(String path) {
+        List<URL> paths = new ArrayList<>();
+        for (String entry: path.split(File.pathSeparator)) {
+            Path p = Paths.get(entry);
+            try {
+                p = p.toRealPath();
+            } catch (IOException x) {
+                p = p.toAbsolutePath();
+            }
+            try {
+                paths.add(p.toUri().toURL());
+            } catch (MalformedURLException e) {
+                //ignore / skip entry
+            }
+        }
+        return paths.toArray(new URL[0]);
+    }
+
+    /**
      * Main program to start a registry. <br>
      * The port number can be specified on the command line.
      */
@@ -362,7 +391,7 @@
             if (envcp == null) {
                 envcp = ".";            // preserve old default behavior
             }
-            URL[] urls = sun.misc.URLClassPath.pathToURLs(envcp);
+            URL[] urls = pathToURLs(envcp);
             ClassLoader cl = new URLClassLoader(urls);
 
             /*