8228773: URLClassLoader constructors should include API note warning that the parent should not be null

Reviewed-by: alanb, mullan
This commit is contained in:
Jaikiran Pai 2025-05-31 13:02:58 +00:00
parent 3a3ea7e17f
commit 84002d12ed
2 changed files with 57 additions and 15 deletions

View File

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 1997, 2024, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 1997, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -77,8 +77,15 @@ public class URLClassLoader extends SecureClassLoader implements Closeable {
* the URL is assumed to refer to a JAR file which will be downloaded and * the URL is assumed to refer to a JAR file which will be downloaded and
* opened as needed. * opened as needed.
* *
* @apiNote If {@code parent} is specified as {@code null} (for the
* bootstrap class loader) then there is no guarantee that all platform
* classes are visible.
* See {@linkplain ClassLoader##builtinLoaders Run-time Built-in Class Loaders}
* for information on the bootstrap class loader and other built-in class loaders.
*
* @param urls the URLs from which to load classes and resources * @param urls the URLs from which to load classes and resources
* @param parent the parent class loader for delegation * @param parent the parent class loader for delegation, can be {@code null}
* for the bootstrap class loader
* @throws NullPointerException if {@code urls} or any of its * @throws NullPointerException if {@code urls} or any of its
* elements is {@code null}. * elements is {@code null}.
*/ */
@ -89,12 +96,12 @@ public class URLClassLoader extends SecureClassLoader implements Closeable {
/** /**
* Constructs a new URLClassLoader for the specified URLs using the * Constructs a new URLClassLoader for the specified URLs using the
* default delegation parent {@code ClassLoader}. The URLs will * {@linkplain ClassLoader#getSystemClassLoader() system class loader
* be searched in the order specified for classes and resources after * as the parent}. The URLs will be searched in the order
* first searching in the parent class loader. Any URL that ends with * specified for classes and resources after first searching in the
* a '/' is assumed to refer to a directory. Otherwise, the URL is * parent class loader. Any URL that ends with a '/' is assumed to
* assumed to refer to a JAR file which will be downloaded and opened * refer to a directory. Otherwise, the URL is assumed to refer to
* as needed. * a JAR file which will be downloaded and opened as needed.
* *
* @param urls the URLs from which to load classes and resources * @param urls the URLs from which to load classes and resources
* *
@ -113,8 +120,15 @@ public class URLClassLoader extends SecureClassLoader implements Closeable {
* factory argument will be used as the stream handler factory to * factory argument will be used as the stream handler factory to
* obtain protocol handlers when creating new jar URLs. * obtain protocol handlers when creating new jar URLs.
* *
* @apiNote If {@code parent} is specified as {@code null} (for the
* bootstrap class loader) then there is no guarantee that all platform
* classes are visible.
* See {@linkplain ClassLoader##builtinLoaders Run-time Built-in Class Loaders}
* for information on the bootstrap class loader and other built-in class loaders.
*
* @param urls the URLs from which to load classes and resources * @param urls the URLs from which to load classes and resources
* @param parent the parent class loader for delegation * @param parent the parent class loader for delegation, can be {@code null}
* for the bootstrap class loader
* @param factory the URLStreamHandlerFactory to use when creating URLs * @param factory the URLStreamHandlerFactory to use when creating URLs
* *
* @throws NullPointerException if {@code urls} or any of its * @throws NullPointerException if {@code urls} or any of its
@ -135,9 +149,16 @@ public class URLClassLoader extends SecureClassLoader implements Closeable {
* Otherwise, the URL is assumed to refer to a JAR file which will be * Otherwise, the URL is assumed to refer to a JAR file which will be
* downloaded and opened as needed. * downloaded and opened as needed.
* *
* @apiNote If {@code parent} is specified as {@code null} (for the
* bootstrap class loader) then there is no guarantee that all platform
* classes are visible.
* See {@linkplain ClassLoader##builtinLoaders Run-time Built-in Class Loaders}
* for information on the bootstrap class loader and other built-in class loaders.
*
* @param name class loader name; or {@code null} if not named * @param name class loader name; or {@code null} if not named
* @param urls the URLs from which to load classes and resources * @param urls the URLs from which to load classes and resources
* @param parent the parent class loader for delegation * @param parent the parent class loader for delegation, can be {@code null}
* for the bootstrap class loader
* *
* @throws IllegalArgumentException if the given name is empty. * @throws IllegalArgumentException if the given name is empty.
* @throws NullPointerException if {@code urls} or any of its * @throws NullPointerException if {@code urls} or any of its
@ -159,9 +180,16 @@ public class URLClassLoader extends SecureClassLoader implements Closeable {
* The factory argument will be used as the stream handler factory to * The factory argument will be used as the stream handler factory to
* obtain protocol handlers when creating new jar URLs. * obtain protocol handlers when creating new jar URLs.
* *
* @apiNote If {@code parent} is specified as {@code null} (for the
* bootstrap class loader) then there is no guarantee that all platform
* classes are visible.
* See {@linkplain ClassLoader##builtinLoaders Run-time Built-in Class Loaders}
* for information on the bootstrap class loader and other built-in class loaders.
*
* @param name class loader name; or {@code null} if not named * @param name class loader name; or {@code null} if not named
* @param urls the URLs from which to load classes and resources * @param urls the URLs from which to load classes and resources
* @param parent the parent class loader for delegation * @param parent the parent class loader for delegation, can be {@code null}
* for the bootstrap class loader
* @param factory the URLStreamHandlerFactory to use when creating URLs * @param factory the URLStreamHandlerFactory to use when creating URLs
* *
* @throws IllegalArgumentException if the given name is empty. * @throws IllegalArgumentException if the given name is empty.

View File

@ -64,15 +64,22 @@ public class SecureClassLoader extends ClassLoader {
* Creates a new {@code SecureClassLoader} using the specified parent * Creates a new {@code SecureClassLoader} using the specified parent
* class loader for delegation. * class loader for delegation.
* *
* @param parent the parent ClassLoader * @apiNote If {@code parent} is specified as {@code null} (for the
* bootstrap class loader) then there is no guarantee that all platform
* classes are visible.
* See {@linkplain ClassLoader##builtinLoaders Run-time Built-in Class Loaders}
* for information on the bootstrap class loader and other built-in class loaders.
*
* @param parent the parent ClassLoader, can be {@code null} for the bootstrap
* class loader
*/ */
protected SecureClassLoader(ClassLoader parent) { protected SecureClassLoader(ClassLoader parent) {
super(parent); super(parent);
} }
/** /**
* Creates a new {@code SecureClassLoader} using the default parent class * Creates a new {@code SecureClassLoader} using the
* loader for delegation. * {@linkplain ClassLoader#getSystemClassLoader() system class loader as the parent}.
*/ */
protected SecureClassLoader() { protected SecureClassLoader() {
super(); super();
@ -82,8 +89,15 @@ public class SecureClassLoader extends ClassLoader {
* Creates a new {@code SecureClassLoader} of the specified name and * Creates a new {@code SecureClassLoader} of the specified name and
* using the specified parent class loader for delegation. * using the specified parent class loader for delegation.
* *
* @apiNote If {@code parent} is specified as {@code null} (for the
* bootstrap class loader) then there is no guarantee that all platform
* classes are visible.
* See {@linkplain ClassLoader##builtinLoaders Run-time Built-in Class Loaders}
* for information on the bootstrap class loader and other built-in class loaders.
*
* @param name class loader name; or {@code null} if not named * @param name class loader name; or {@code null} if not named
* @param parent the parent class loader * @param parent the parent class loader, can be {@code null} for the bootstrap
* class loader
* *
* @throws IllegalArgumentException if the given name is empty. * @throws IllegalArgumentException if the given name is empty.
* *