< prev index next >

jdk/src/java.base/share/classes/java/lang/ClassLoader.java

Print this page

        

*** 220,229 **** --- 220,232 ---- // The parent class loader for delegation // Note: VM hardcoded the offset of this field, thus all new fields // must be added *after* it. private final ClassLoader parent; + // class loader name + private final String name; + // the unnamed module for this ClassLoader private final Module unnamedModule; /** * Encapsulates the set of parallel capable loader types.
*** 329,346 **** } return p; } private static Void checkCreateClassLoader() { SecurityManager security = System.getSecurityManager(); if (security != null) { security.checkCreateClassLoader(); } return null; } ! private ClassLoader(Void unused, ClassLoader parent) { this.parent = parent; this.unnamedModule = SharedSecrets.getJavaLangReflectModuleAccess() .defineUnnamedModule(this); if (ParallelLoaders.isRegistered(this.getClass())) { --- 332,358 ---- } return p; } private static Void checkCreateClassLoader() { + return checkCreateClassLoader(null); + } + + private static Void checkCreateClassLoader(String name) { + if (name != null && name.isEmpty()) { + throw new IllegalArgumentException("name must be non-empty or null"); + } + SecurityManager security = System.getSecurityManager(); if (security != null) { security.checkCreateClassLoader(); } return null; } ! private ClassLoader(Void unused, String name, ClassLoader parent) { ! this.name = name; this.parent = parent; this.unnamedModule = SharedSecrets.getJavaLangReflectModuleAccess() .defineUnnamedModule(this); if (ParallelLoaders.isRegistered(this.getClass())) {
*** 354,363 **** --- 366,396 ---- assertionLock = this; } } /** + * Creates a new class loader of the specified name and using the + * specified parent class loader for delegation. + * + * @param name class loader name; or {@code null} if not named + * @param parent the parent class loader + * + * @throws IllegalArgumentException if the given name is empty. + * + * @throws SecurityException + * If a security manager exists and its + * {@link SecurityManager#checkCreateClassLoader()} + * method doesn't allow creation of a new class loader. + * + * @since 9 + */ + protected ClassLoader(String name, ClassLoader parent) { + this(checkCreateClassLoader(name), name, parent); + } + + + /** * Creates a new class loader using the specified parent class loader for * delegation. * * <p> If there is a security manager, its {@link * SecurityManager#checkCreateClassLoader()
*** 373,385 **** * of a new class loader. * * @since 1.2 */ protected ClassLoader(ClassLoader parent) { ! this(checkCreateClassLoader(), parent); } /** * Creates a new class loader using the <tt>ClassLoader</tt> returned by * the method {@link #getSystemClassLoader() * <tt>getSystemClassLoader()</tt>} as the parent class loader. * --- 406,419 ---- * of a new class loader. * * @since 1.2 */ protected ClassLoader(ClassLoader parent) { ! this(checkCreateClassLoader(), null, parent); } + /** * Creates a new class loader using the <tt>ClassLoader</tt> returned by * the method {@link #getSystemClassLoader() * <tt>getSystemClassLoader()</tt>} as the parent class loader. *
*** 392,402 **** * If a security manager exists and its * <tt>checkCreateClassLoader</tt> method doesn't allow creation * of a new class loader. */ protected ClassLoader() { ! this(checkCreateClassLoader(), getSystemClassLoader()); } // -- Class -- /** --- 426,460 ---- * If a security manager exists and its * <tt>checkCreateClassLoader</tt> method doesn't allow creation * of a new class loader. */ protected ClassLoader() { ! this(checkCreateClassLoader(), null, getSystemClassLoader()); ! } ! ! ! /** ! * Returns the name of this class loader or {@code null} if ! * this class loader is not named. ! * ! * @apiNote This method is non-final for compatibility. If this ! * method is overridden, this method must return the same name ! * as specified when this class loader was instantiated. ! * ! * @return name of this class loader; or {@code null} if ! * this class loader is not named. ! * ! * @since 9 ! */ ! public String getName() { ! return name; ! } ! ! // package-private used by StackTraceElement to avoid ! // calling the overrideable getName method ! final String name() { ! return name; } // -- Class -- /**
*** 1626,1635 **** --- 1684,1696 ---- /** * Returns the platform class loader for delegation. All * <a href="#builtinLoaders">platform classes</a> are visible to * the platform class loader. * + * @implNote The name of the builtin platform class loader is + * {@code "platform"}. + * * @return The platform {@code ClassLoader}. * * @throws SecurityException * If a security manager is present, and the caller's class loader is * not {@code null}, and the caller's class loader is not the same
*** 1679,1689 **** * @implNote The system property to override the system class loader is not * examined until the VM is almost fully initialized. Code that executes * this method during startup should take care not to cache the return * value until the system is fully initialized. * ! * <p> The class path used by the built-in system class loader is determined * by the system property "{@code java.class.path}" during early * initialization of the VM. If the system property is not defined, * or its value is an empty string, then there is no class path * when the initial module is a module on the application module path, * i.e. <em>a named module</em>. If the initial module is not on --- 1740,1751 ---- * @implNote The system property to override the system class loader is not * examined until the VM is almost fully initialized. Code that executes * this method during startup should take care not to cache the return * value until the system is fully initialized. * ! * <p> The name of the built-in system class loader is {@code "app"}. ! * The class path used by the built-in system class loader is determined * by the system property "{@code java.class.path}" during early * initialization of the VM. If the system property is not defined, * or its value is an empty string, then there is no class path * when the initial module is a module on the application module path, * i.e. <em>a named module</em>. If the initial module is not on
< prev index next >