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

Print this page
rev 13958 : 8152190: Move sun.misc.JarIndex and InvalidJarIndexException to an internal package
Reviewed-by:


  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 sun.misc.InvalidJarIndexException;
  69 import sun.misc.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(


 885                      * jars incorporates a check for presence in the hashmap
 886                      */
 887                     boolean visitedURL = !visited.add(URLUtil.urlNoFragString(url));
 888                     if (!visitedURL) {
 889                         try {
 890                             newLoader.ensureOpen();
 891                         } catch (IOException e) {
 892                             throw new InternalError(e);
 893                         }
 894                         final JarEntry entry = newLoader.jar.getJarEntry(name);
 895                         if (entry != null) {
 896                             return newLoader.checkResource(name, check, entry);
 897                         }
 898 
 899                         /* Verify that at least one other resource with the
 900                          * same package name as the lookedup resource is
 901                          * present in the new jar
 902                          */
 903                         if (!newLoader.validIndex(name)) {
 904                             /* the mapping is wrong */
 905                             throw new InvalidJarIndexException("Invalid index");
 906                         }
 907                     }
 908 
 909                     /* If newLoader is the current loader or if it is a
 910                      * loader that has already been searched or if the new
 911                      * loader does not have an index then skip it
 912                      * and move on to the next loader.
 913                      */
 914                     if (visitedURL || newLoader == this ||
 915                             newLoader.getIndex() == null) {
 916                         continue;
 917                     }
 918 
 919                     /* Process the index of the new loader
 920                      */
 921                     if((res = newLoader.getResource(name, check, visited))
 922                             != null) {
 923                         return res;
 924                     }
 925                 }




  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(


 885                      * jars incorporates a check for presence in the hashmap
 886                      */
 887                     boolean visitedURL = !visited.add(URLUtil.urlNoFragString(url));
 888                     if (!visitedURL) {
 889                         try {
 890                             newLoader.ensureOpen();
 891                         } catch (IOException e) {
 892                             throw new InternalError(e);
 893                         }
 894                         final JarEntry entry = newLoader.jar.getJarEntry(name);
 895                         if (entry != null) {
 896                             return newLoader.checkResource(name, check, entry);
 897                         }
 898 
 899                         /* Verify that at least one other resource with the
 900                          * same package name as the lookedup resource is
 901                          * present in the new jar
 902                          */
 903                         if (!newLoader.validIndex(name)) {
 904                             /* the mapping is wrong */
 905                             throw new InvalidJarIndexError("Invalid index");
 906                         }
 907                     }
 908 
 909                     /* If newLoader is the current loader or if it is a
 910                      * loader that has already been searched or if the new
 911                      * loader does not have an index then skip it
 912                      * and move on to the next loader.
 913                      */
 914                     if (visitedURL || newLoader == this ||
 915                             newLoader.getIndex() == null) {
 916                         continue;
 917                     }
 918 
 919                     /* Process the index of the new loader
 920                      */
 921                     if((res = newLoader.getResource(name, check, visited))
 922                             != null) {
 923                         return res;
 924                     }
 925                 }