< prev index next >

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

Print this page
8198481: Coding style cleanups for src/java.base/share/classes/jdk/internal/loader/ClassLoaders.java
Reviewed-by: mchung, alanb


  39 
  40 /**
  41  * Creates and provides access to the built-in platform and application class
  42  * loaders. It also creates the class loader that is used to locate resources
  43  * in modules defined to the boot class loader.
  44  */
  45 public class ClassLoaders {
  46 
  47     private ClassLoaders() { }
  48 
  49     private static final JavaLangAccess JLA = SharedSecrets.getJavaLangAccess();
  50 
  51     // the built-in class loaders
  52     private static final BootClassLoader BOOT_LOADER;
  53     private static final PlatformClassLoader PLATFORM_LOADER;
  54     private static final AppClassLoader APP_LOADER;
  55 
  56     // Creates the built-in class loaders.
  57     static {
  58         // -Xbootclasspath/a or -javaagent with Boot-Class-Path attribute
  59         String s = VM.getSavedProperty("jdk.boot.class.path.append");
  60         BOOT_LOADER = new BootClassLoader((s != null && s.length() > 0)
  61                                           ? new URLClassPath(s, true)

  62                                           : null);
  63         PLATFORM_LOADER = new PlatformClassLoader(BOOT_LOADER);
  64 
  65         // A class path is required when no main module is specified.
  66         // In this case the class path defaults to "", meaning the
  67         // current working directory. When a main module is specified,
  68         // on the contrary, we drop this historic interpretation of
  69         // the empty string and instead treat it as unspecified.
  70         String cp = System.getProperty("java.class.path");
  71         if (cp == null || cp.length() == 0) {
  72             String mainMid = System.getProperty("jdk.module.main");
  73             cp = (mainMid == null) ? "" : null;
  74         }
  75         URLClassPath ucp = new URLClassPath(cp, false);
  76         APP_LOADER = new AppClassLoader(PLATFORM_LOADER, ucp);
  77     }
  78 
  79     /**
  80      * Returns the class loader that is used to find resources in modules
  81      * defined to the boot class loader.
  82      *
  83      * @apiNote This method is not public, it should instead be used via
  84      * the BootLoader class that provides a restricted API to this class
  85      * loader.
  86      */
  87     static BuiltinClassLoader bootLoader() {
  88         return BOOT_LOADER;
  89     }
  90 
  91     /**
  92      * Returns the platform class loader.
  93      */




  39 
  40 /**
  41  * Creates and provides access to the built-in platform and application class
  42  * loaders. It also creates the class loader that is used to locate resources
  43  * in modules defined to the boot class loader.
  44  */
  45 public class ClassLoaders {
  46 
  47     private ClassLoaders() { }
  48 
  49     private static final JavaLangAccess JLA = SharedSecrets.getJavaLangAccess();
  50 
  51     // the built-in class loaders
  52     private static final BootClassLoader BOOT_LOADER;
  53     private static final PlatformClassLoader PLATFORM_LOADER;
  54     private static final AppClassLoader APP_LOADER;
  55 
  56     // Creates the built-in class loaders.
  57     static {
  58         // -Xbootclasspath/a or -javaagent with Boot-Class-Path attribute
  59         String append = VM.getSavedProperty("jdk.boot.class.path.append");
  60         BOOT_LOADER = new BootClassLoader(
  61                 (append != null && append.length() > 0)
  62                 ? new URLClassPath(append, true)
  63                 : null);
  64         PLATFORM_LOADER = new PlatformClassLoader(BOOT_LOADER);
  65 
  66         // A class path is required when no main module is specified.
  67         // In this case the class path defaults to "", meaning the
  68         // current working directory. When a main module is specified,
  69         // on the contrary, we drop this historic interpretation of
  70         // the empty string and instead treat it as unspecified.
  71         String cp = System.getProperty("java.class.path");
  72         if (cp == null || cp.length() == 0) {
  73             String mainModuleName = System.getProperty("jdk.module.main");
  74             cp = (mainModuleName == null) ? "" : null;
  75         }
  76         URLClassPath ucp = new URLClassPath(cp, false);
  77         APP_LOADER = new AppClassLoader(PLATFORM_LOADER, ucp);
  78     }
  79 
  80     /**
  81      * Returns the class loader that is used to find resources in modules
  82      * defined to the boot class loader.
  83      *
  84      * @apiNote This method is not public, it should instead be used via
  85      * the BootLoader class that provides a restricted API to this class
  86      * loader.
  87      */
  88     static BuiltinClassLoader bootLoader() {
  89         return BOOT_LOADER;
  90     }
  91 
  92     /**
  93      * Returns the platform class loader.
  94      */


< prev index next >