src/java.rmi/share/classes/sun/rmi/registry/RegistryImpl.java
Print this page
rev 13943 : 8152277: Move URLClassPath.pathToURLs(String) to RegistryImpl
Reviewed-by: alanb
*** 23,36 ****
--- 23,41 ----
* questions.
*/
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.*;
import java.rmi.*;
import java.rmi.server.ObjID;
*** 331,340 ****
--- 336,369 ----
return (val);
}
}
/**
+ * 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.
*/
public static void main(String args[])
{
*** 360,370 ****
*/
String envcp = System.getProperty("env.class.path");
if (envcp == null) {
envcp = "."; // preserve old default behavior
}
! URL[] urls = sun.misc.URLClassPath.pathToURLs(envcp);
ClassLoader cl = new URLClassLoader(urls);
/*
* Fix bugid 4242317: Classes defined by this class loader should
* be annotated with the value of the "java.rmi.server.codebase"
--- 389,399 ----
*/
String envcp = System.getProperty("env.class.path");
if (envcp == null) {
envcp = "."; // preserve old default behavior
}
! URL[] urls = pathToURLs(envcp);
ClassLoader cl = new URLClassLoader(urls);
/*
* Fix bugid 4242317: Classes defined by this class loader should
* be annotated with the value of the "java.rmi.server.codebase"