changeset 13952:ed1ac70edb86

8152277: Move URLClassPath.pathToURLs(String) to RegistryImpl Reviewed-by: alanb
author chegar
date Thu, 24 Mar 2016 11:59:07 +0000
parents 8bdb63271ed2
children a18dbcbe2e1a ecd6e985e8b2
files src/java.base/share/classes/sun/misc/URLClassPath.java src/java.rmi/share/classes/sun/rmi/registry/RegistryImpl.java
diffstat 2 files changed, 30 insertions(+), 31 deletions(-) [+]
line wrap: on
line diff
--- a/src/java.base/share/classes/sun/misc/URLClassPath.java	Thu Mar 24 11:56:47 2016 +0000
+++ b/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/src/java.rmi/share/classes/sun/rmi/registry/RegistryImpl.java	Thu Mar 24 11:56:47 2016 +0000
+++ b/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);
 
             /*