< prev index next >

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

Print this page

        

*** 205,214 **** --- 205,216 ---- * * @jls 6.7 Fully Qualified Names * @jls 13.1 The Form of a Binary * @see #resolveClass(Class) * @since 1.0 + * @revised 9 + * @spec JPMS */ public abstract class ClassLoader { private static native void registerNatives(); static {
*** 378,393 **** * 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 --- 380,395 ---- * If a security manager exists and its * {@link SecurityManager#checkCreateClassLoader()} * method doesn't allow creation of a new class loader. * * @since 9 + * @spec JPMS */ 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
*** 438,447 **** --- 440,450 ---- * * @return name of this class loader; or {@code null} if * this class loader is not named. * * @since 9 + * @spec JPMS */ public String getName() { return name; }
*** 708,717 **** --- 711,721 ---- * * @return The resulting {@code Class} object, or {@code null} * if the class could not be found. * * @since 9 + * @spec JPMS */ protected Class<?> findClass(String moduleName, String name) { if (moduleName == null) { try { return findClass(name);
*** 832,841 **** --- 836,847 ---- * @see #resolveClass(Class) * @see java.security.CodeSource * @see java.security.SecureClassLoader * * @since 1.1 + * @revised 9 + * @spec JPMS */ protected final Class<?> defineClass(String name, byte[] b, int off, int len) throws ClassFormatError { return defineClass(name, b, off, len, null);
*** 965,974 **** --- 971,983 ---- * If an attempt is made to add this class to a package that * contains classes that were signed by a different set of * certificates than this class, or if {@code name} begins with * "{@code java.}" and this class loader is not the platform * class loader or its ancestor. + * + * @revised 9 + * @spec JPMS */ protected final Class<?> defineClass(String name, byte[] b, int off, int len, ProtectionDomain protectionDomain) throws ClassFormatError {
*** 1039,1048 **** --- 1048,1059 ---- * "{@code java.}". * * @see #defineClass(String, byte[], int, int, ProtectionDomain) * * @since 1.5 + * @revised 9 + * @spec JPMS */ protected final Class<?> defineClass(String name, java.nio.ByteBuffer b, ProtectionDomain protectionDomain) throws ClassFormatError {
*** 1262,1276 **** /** * Returns a URL to a resource in a module defined to this class loader. * Class loader implementations that support the loading from modules * should override this method. * ! * @apiNote This method is the basis for the {@code Class} {@link ! * Class#getResource getResource} and {@link Class#getResourceAsStream ! * getResourceAsStream} methods. It is not subject to the rules for ! * encapsulation specified by {@code Module} {@link ! * Module#getResourceAsStream getResourceAsStream}. * * @implSpec The default implementation attempts to find the resource by * invoking {@link #findResource(String)} when the {@code moduleName} is * {@code null}. It otherwise returns {@code null}. * --- 1273,1287 ---- /** * Returns a URL to a resource in a module defined to this class loader. * Class loader implementations that support the loading from modules * should override this method. * ! * @apiNote This method is the basis for the {@link ! * Class#getResource Class.getResource}, {@link Class#getResourceAsStream ! * Class.getResourceAsStream}, and {@link Module#getResourceAsStream ! * Module.getResourceAsStream} methods. It is not subject to the rules for ! * encapsulation specified by {@code Module.getResourceAsStream}. * * @implSpec The default implementation attempts to find the resource by * invoking {@link #findResource(String)} when the {@code moduleName} is * {@code null}. It otherwise returns {@code null}. *
*** 1290,1299 **** --- 1301,1311 ---- * @throws IOException * If I/O errors occur * * @see java.lang.module.ModuleReader#find(String) * @since 9 + * @spec JPMS */ protected URL findResource(String moduleName, String name) throws IOException { if (moduleName == null) { return findResource(name); } else {
*** 1340,1349 **** --- 1352,1363 ---- * denied by the security manager. * * @throws NullPointerException If {@code name} is {@code null} * * @since 1.1 + * @revised 9 + * @spec JPMS */ public URL getResource(String name) { Objects.requireNonNull(name); URL url; if (parent != null) {
*** 1401,1410 **** --- 1415,1426 ---- * @throws NullPointerException If {@code name} is {@code null} * * @see #findResources(String) * * @since 1.2 + * @revised 9 + * @spec JPMS */ public Enumeration<URL> getResources(String name) throws IOException { Objects.requireNonNull(name); @SuppressWarnings("unchecked") Enumeration<URL>[] tmp = (Enumeration<URL>[]) new Enumeration<?>[2];
*** 1497,1506 **** --- 1513,1524 ---- * constructed to locate the resource, the resource is in a package * that is not opened unconditionally, or access to the resource is * denied by the security manager. * * @since 1.2 + * @revised 9 + * @spec JPMS */ protected URL findResource(String name) { return null; }
*** 1529,1538 **** --- 1547,1558 ---- * * @throws IOException * If I/O errors occur * * @since 1.2 + * @revised 9 + * @spec JPMS */ protected Enumeration<URL> findResources(String name) throws IOException { return Collections.emptyEnumeration(); }
*** 1599,1608 **** --- 1619,1630 ---- * constructed to locate the resource, the resource is in a package * that is not opened unconditionally or access to the resource is * denied by the security manager. * * @since 1.1 + * @revised 9 + * @spec JPMS */ public static URL getSystemResource(String name) { return getSystemClassLoader().getResource(name); }
*** 1634,1643 **** --- 1656,1667 ---- * * @throws IOException * If I/O errors occur * * @since 1.2 + * @revised 9 + * @spec JPMS */ public static Enumeration<URL> getSystemResources(String name) throws IOException { return getSystemClassLoader().getResources(name);
*** 1665,1674 **** --- 1689,1700 ---- * denied by the security manager. * * @throws NullPointerException If {@code name} is {@code null} * * @since 1.1 + * @revised 9 + * @spec JPMS */ public InputStream getResourceAsStream(String name) { Objects.requireNonNull(name); URL url = getResource(name); try {
*** 1697,1706 **** --- 1723,1734 ---- * resource could not be found, the resource is in a package that * is not opened unconditionally, or access to the resource is * denied by the security manager. * * @since 1.1 + * @revised 9 + * @spec JPMS */ public static InputStream getSystemResourceAsStream(String name) { URL url = getSystemResource(name); try { return url != null ? url.openStream() : null;
*** 1747,1756 **** --- 1775,1785 ---- * * @return The unnamed Module for this class loader * * @see Module#isNamed() * @since 9 + * @spec JPMS */ public final Module getUnnamedModule() { return unnamedModule; }
*** 1770,1779 **** --- 1799,1809 ---- * as or an ancestor of the platform class loader, * and the caller does not have the * {@link RuntimePermission}{@code ("getClassLoader")} * * @since 9 + * @spec JPMS */ @CallerSensitive public static ClassLoader getPlatformClassLoader() { SecurityManager sm = System.getSecurityManager(); ClassLoader loader = getBuiltinPlatformClassLoader();
*** 1845,1854 **** --- 1875,1886 ---- * exception is thrown by that constructor when it is invoked. The * underlying cause of the error can be retrieved via the * {@link Throwable#getCause()} method. * * @revised 1.4 + * @revised 9 + * @spec JPMS */ @CallerSensitive public static ClassLoader getSystemClassLoader() { switch (VM.initLevel()) { case 0:
*** 2099,2108 **** --- 2131,2142 ---- * @throws IllegalArgumentException * if a package of the given {@code name} is already * defined by this class loader * * @since 1.2 + * @revised 9 + * @spec JPMS * * @see <a href="../../../technotes/guides/jar/jar.html#versioning"> * The JAR File Specification: Package Versioning</a> * @see <a href="../../../technotes/guides/jar/jar.html#sealing"> * The JAR File Specification: Package Sealing</a>
*** 2136,2145 **** --- 2170,2180 ---- * * @throws NullPointerException * if {@code name} is {@code null}. * * @since 9 + * @spec JPMS */ public final Package getDefinedPackage(String name) { Objects.requireNonNull(name, "name cannot be null"); NamedPackage p = packages.get(name);
*** 2158,2167 **** --- 2193,2203 ---- * * @return The array of {@code Package} objects defined by this class loader; * or an zero length array if no package has been defined by this class loader. * * @since 9 + * @spec JPMS */ public final Package[] getDefinedPackages() { return packages().toArray(Package[]::new); }
*** 2194,2203 **** --- 2230,2241 ---- * a child loader. A more robust approach is to use the * {@link ClassLoader#getDefinedPackage} method which returns * a {@code Package} for the specified class loader. * * @since 1.2 + * @revised 9 + * @spec JPMS */ @Deprecated(since="9") protected Package getPackage(String name) { Package pkg = getDefinedPackage(name); if (pkg == null) {
*** 2218,2227 **** --- 2256,2267 ---- * * @return The array of {@code Package} objects defined by this * class loader and its ancestors * * @since 1.2 + * @revised 9 + * @spec JPMS */ protected Package[] getPackages() { Stream<Package> pkgs = packages(); ClassLoader ld = parent; while (ld != null) {
< prev index next >