< prev index next >

src/java.base/share/classes/jdk/internal/loader/URLClassPath.java

Print this page
rev 14210 : 8154231: Simplify access to System properties from JDK code
Reviewed-by: rriggs


  35 import java.net.JarURLConnection;
  36 import java.net.MalformedURLException;
  37 import java.net.URL;
  38 import java.net.URLConnection;
  39 import java.net.URLStreamHandler;
  40 import java.net.URLStreamHandlerFactory;
  41 import java.security.AccessControlException;
  42 import java.security.AccessController;
  43 import java.security.CodeSigner;
  44 import java.security.Permission;
  45 import java.security.PrivilegedExceptionAction;
  46 import java.security.cert.Certificate;
  47 import java.util.ArrayList;
  48 import java.util.Collections;
  49 import java.util.Enumeration;
  50 import java.util.HashMap;
  51 import java.util.HashSet;
  52 import java.util.LinkedList;
  53 import java.util.List;
  54 import java.util.NoSuchElementException;

  55 import java.util.Set;
  56 import java.util.Stack;
  57 import java.util.StringTokenizer;
  58 import java.util.jar.JarFile;
  59 import java.util.zip.ZipEntry;
  60 import java.util.jar.JarEntry;
  61 import java.util.jar.Manifest;
  62 import java.util.jar.Attributes;
  63 import java.util.jar.Attributes.Name;
  64 import java.util.zip.ZipFile;
  65 
  66 import jdk.internal.misc.JavaUtilZipFileAccess;
  67 import jdk.internal.misc.SharedSecrets;
  68 import jdk.internal.util.jar.InvalidJarIndexError;
  69 import jdk.internal.util.jar.JarIndex;
  70 import sun.net.util.URLUtil;
  71 import sun.net.www.ParseUtil;

  72 
  73 /**
  74  * This class is used to maintain a search path of URLs for loading classes
  75  * and resources from both JAR files and directories.
  76  *
  77  * @author  David Connelly
  78  */
  79 public class URLClassPath {
  80     private static final String USER_AGENT_JAVA_VERSION = "UA-Java-Version";
  81     private static final String JAVA_HOME;
  82     private static final String JAVA_VERSION;
  83     private static final boolean DEBUG;
  84     private static final boolean DISABLE_JAR_CHECKING;
  85 
  86     static {
  87         JAVA_HOME = java.security.AccessController.doPrivileged(
  88             new sun.security.action.GetPropertyAction("java.home"));
  89         JAVA_VERSION = java.security.AccessController.doPrivileged(
  90             new sun.security.action.GetPropertyAction("java.version"));
  91         DEBUG        = (java.security.AccessController.doPrivileged(
  92             new sun.security.action.GetPropertyAction("sun.misc.URLClassPath.debug")) != null);
  93         String p = java.security.AccessController.doPrivileged(
  94             new sun.security.action.GetPropertyAction("sun.misc.URLClassPath.disableJarChecking"));
  95         DISABLE_JAR_CHECKING = p != null ? p.equals("true") || p.equals("") : false;
  96     }
  97 
  98     /* The original search path of URLs. */
  99     private ArrayList<URL> path = new ArrayList<>();
 100 
 101     /* The stack of unopened URLs */
 102     Stack<URL> urls = new Stack<>();
 103 
 104     /* The resulting search path of Loaders */
 105     ArrayList<Loader> loaders = new ArrayList<>();
 106 
 107     /* Map of each URL opened to its corresponding Loader */
 108     HashMap<String, Loader> lmap = new HashMap<>();
 109 
 110     /* The jar protocol handler to use when creating new URLs */
 111     private URLStreamHandler jarHandler;
 112 
 113     /* Whether this URLClassLoader has been closed yet */
 114     private boolean closed = false;




  35 import java.net.JarURLConnection;
  36 import java.net.MalformedURLException;
  37 import java.net.URL;
  38 import java.net.URLConnection;
  39 import java.net.URLStreamHandler;
  40 import java.net.URLStreamHandlerFactory;
  41 import java.security.AccessControlException;
  42 import java.security.AccessController;
  43 import java.security.CodeSigner;
  44 import java.security.Permission;
  45 import java.security.PrivilegedExceptionAction;
  46 import java.security.cert.Certificate;
  47 import java.util.ArrayList;
  48 import java.util.Collections;
  49 import java.util.Enumeration;
  50 import java.util.HashMap;
  51 import java.util.HashSet;
  52 import java.util.LinkedList;
  53 import java.util.List;
  54 import java.util.NoSuchElementException;
  55 import java.util.Properties;
  56 import java.util.Set;
  57 import java.util.Stack;
  58 import java.util.StringTokenizer;
  59 import java.util.jar.JarFile;
  60 import java.util.zip.ZipEntry;
  61 import java.util.jar.JarEntry;
  62 import java.util.jar.Manifest;
  63 import java.util.jar.Attributes;
  64 import java.util.jar.Attributes.Name;
  65 import java.util.zip.ZipFile;
  66 
  67 import jdk.internal.misc.JavaUtilZipFileAccess;
  68 import jdk.internal.misc.SharedSecrets;
  69 import jdk.internal.util.jar.InvalidJarIndexError;
  70 import jdk.internal.util.jar.JarIndex;
  71 import sun.net.util.URLUtil;
  72 import sun.net.www.ParseUtil;
  73 import sun.security.action.GetPropertyAction;
  74 
  75 /**
  76  * This class is used to maintain a search path of URLs for loading classes
  77  * and resources from both JAR files and directories.
  78  *
  79  * @author  David Connelly
  80  */
  81 public class URLClassPath {
  82     private static final String USER_AGENT_JAVA_VERSION = "UA-Java-Version";

  83     private static final String JAVA_VERSION;
  84     private static final boolean DEBUG;
  85     private static final boolean DISABLE_JAR_CHECKING;
  86 
  87     static {
  88         Properties props = GetPropertyAction.getProperties();
  89         JAVA_VERSION = props.getProperty("java.version");
  90         DEBUG = (props.getProperty("sun.misc.URLClassPath.debug") != null);
  91         String p = props.getProperty("sun.misc.URLClassPath.disableJarChecking");




  92         DISABLE_JAR_CHECKING = p != null ? p.equals("true") || p.equals("") : false;
  93     }
  94 
  95     /* The original search path of URLs. */
  96     private ArrayList<URL> path = new ArrayList<>();
  97 
  98     /* The stack of unopened URLs */
  99     Stack<URL> urls = new Stack<>();
 100 
 101     /* The resulting search path of Loaders */
 102     ArrayList<Loader> loaders = new ArrayList<>();
 103 
 104     /* Map of each URL opened to its corresponding Loader */
 105     HashMap<String, Loader> lmap = new HashMap<>();
 106 
 107     /* The jar protocol handler to use when creating new URLs */
 108     private URLStreamHandler jarHandler;
 109 
 110     /* Whether this URLClassLoader has been closed yet */
 111     private boolean closed = false;


< prev index next >