160160 * other members are the classes and interfaces whose declarations are
161161 * enclosed within the top-level class declaration.
162162 *
163+ * <p> Unless otherwise specified, methods in this class throw a
164+ * {@link NullPointerException} when they are called with {@code null}
165+ * or an array that contains {@code null} as an argument.
166+ *
163167 * <h2><a id=hiddenClasses>Hidden Classes</a></h2>
164168 * A class or interface created by the invocation of
165169 * {@link java.lang.invoke.MethodHandles.Lookup#defineHiddenClass(byte[], boolean, MethodHandles.Lookup.ClassOption...)
@@ -530,7 +534,8 @@ private static Class<?> forName(String className, Class<?> caller)
530534 * (which implies linking). See Section {@jls
531535 * 12.4} of <cite>The Java Language
532536 * Specification</cite>.
533- * @param loader class loader from which the class must be loaded
537+ * @param loader class loader from which the class must be loaded,
538+ * may be {@code null}
534539 * @return class object representing the desired class
535540 *
536541 * @throws LinkageError if the linkage fails
@@ -589,8 +594,6 @@ private static native Class<?> forName0(String name, boolean initialize,
589594 * @return {@code Class} object of the given name defined in the given module;
590595 * {@code null} if not found.
591596 *
592- * @throws NullPointerException if the given module or name is {@code null}
593- *
594597 * @throws LinkageError if the linkage fails
595598 *
596599 * @jls 12.2 Loading of Classes and Interfaces
@@ -620,8 +623,6 @@ public static Class<?> forName(Module module, String name) {
620623 *
621624 * @param primitiveName the name of the primitive type to find
622625 *
623- * @throws NullPointerException if the argument is {@code null}
624- *
625626 * @jls 4.2 Primitive Types and Values
626627 * @jls 15.8.2 Class Literals
627628 * @since 22
@@ -757,7 +758,7 @@ public T newInstance()
757758 * this {@code Class} object represents a primitive type, this method
758759 * returns {@code false}.
759760 *
760- * @param obj the object to check
761+ * @param obj the object to check, may be {@code null}
761762 * @return true if {@code obj} is an instance of this class
762763 *
763764 * @since 1.1
@@ -787,8 +788,6 @@ public T newInstance()
787788 * @param cls the {@code Class} object to be checked
788789 * @return the {@code boolean} value indicating whether objects of the
789790 * type {@code cls} can be assigned to objects of this class
790- * @throws NullPointerException if the specified Class parameter is
791- * null.
792791 * @since 1.1
793792 */
794793 @ IntrinsicCandidate
@@ -2057,7 +2056,6 @@ public Constructor<?>[] getConstructors() {
20572056 * {@code name}
20582057 * @throws NoSuchFieldException if a field with the specified name is
20592058 * not found.
2060- * @throws NullPointerException if {@code name} is {@code null}
20612059 *
20622060 * @since 1.1
20632061 * @jls 8.2 Class Members
@@ -2148,13 +2146,13 @@ public Field getField(String name) throws NoSuchFieldException {
21482146 * overriding method as it would have a more specific return type.
21492147 *
21502148 * @param name the name of the method
2151- * @param parameterTypes the list of parameters
2149+ * @param parameterTypes the list of parameters, may be {@code null}
21522150 * @return the {@code Method} object that matches the specified
21532151 * {@code name} and {@code parameterTypes}
2154- * @throws NoSuchMethodException if a matching method is not found
2152+ * @throws NoSuchMethodException if a matching method is not found,
2153+ * if {@code parameterTypes} contains {@code null},
21552154 * or if the name is {@value ConstantDescs#INIT_NAME} or
2156- * {@value ConstantDescs#CLASS_INIT_NAME}.
2157- * @throws NullPointerException if {@code name} is {@code null}
2155+ * {@value ConstantDescs#CLASS_INIT_NAME}
21582156 *
21592157 * @jls 8.2 Class Members
21602158 * @jls 8.4 Method Declarations
@@ -2185,12 +2183,13 @@ public Method getMethod(String name, Class<?>... parameterTypes)
21852183 * represented by this {@code Class} object whose formal parameter
21862184 * types match those specified by {@code parameterTypes}.
21872185 *
2188- * @param parameterTypes the parameter array
2186+ * @param parameterTypes the parameter array, may be {@code null}
21892187 * @return the {@code Constructor} object of the public constructor that
21902188 * matches the specified {@code parameterTypes}
21912189 * @throws NoSuchMethodException if a matching constructor is not found,
2192- * including when this {@code Class} object represents
2193- * an interface, a primitive type, an array class, or void.
2190+ * if this {@code Class} object represents an interface, a primitive
2191+ * type, an array class, or void, or if {@code parameterTypes}
2192+ * contains {@code null}
21942193 *
21952194 * @see #getDeclaredConstructor(Class[])
21962195 * @since 1.1
@@ -2371,7 +2370,6 @@ public Constructor<?>[] getDeclaredConstructors() {
23712370 * class
23722371 * @throws NoSuchFieldException if a field with the specified name is
23732372 * not found.
2374- * @throws NullPointerException if {@code name} is {@code null}
23752373 *
23762374 * @since 1.1
23772375 * @jls 8.2 Class Members
@@ -2406,11 +2404,13 @@ public Field getDeclaredField(String name) throws NoSuchFieldException {
24062404 * method does not find the {@code clone()} method.
24072405 *
24082406 * @param name the name of the method
2409- * @param parameterTypes the parameter array
2410- * @return the {@code Method} object for the method of this class
2411- * matching the specified name and parameters
2412- * @throws NoSuchMethodException if a matching method is not found.
2413- * @throws NullPointerException if {@code name} is {@code null}
2407+ * @param parameterTypes the parameter array, may be {@code null}
2408+ * @return the {@code Method} object for the method of this class
2409+ * matching the specified name and parameters
2410+ * @throws NoSuchMethodException if a matching method is not found,
2411+ * if {@code parameterTypes} contains {@code null},
2412+ * or if the name is {@value ConstantDescs#INIT_NAME} or
2413+ * {@value ConstantDescs#CLASS_INIT_NAME}
24142414 *
24152415 * @jls 8.2 Class Members
24162416 * @jls 8.4 Method Declarations
@@ -2477,12 +2477,13 @@ Method findMethod(boolean publicOnly, String name, Class<?>... parameterTypes) {
24772477 * declared in a non-static context, the formal parameter types
24782478 * include the explicit enclosing instance as the first parameter.
24792479 *
2480- * @param parameterTypes the parameter array
2480+ * @param parameterTypes the parameter array, may be {@code null}
24812481 * @return The {@code Constructor} object for the constructor with the
24822482 * specified parameter list
24832483 * @throws NoSuchMethodException if a matching constructor is not found,
2484- * including when this {@code Class} object represents
2485- * an interface, a primitive type, an array class, or void.
2484+ * if this {@code Class} object represents an interface, a
2485+ * primitive type, an array class, or void, or if
2486+ * {@code parameterTypes} contains {@code null}
24862487 *
24872488 * @see #getConstructor(Class[])
24882489 * @since 1.1
@@ -2541,7 +2542,6 @@ public Constructor<T> getDeclaredConstructor(Class<?>... parameterTypes)
25412542 * resource with this name is found, or the resource is in a package
25422543 * that is not {@linkplain Module#isOpen(String, Module) open} to at
25432544 * least the caller module.
2544- * @throws NullPointerException If {@code name} is {@code null}
25452545 *
25462546 * @see Module#getResourceAsStream(String)
25472547 * @since 1.1
@@ -2637,7 +2637,6 @@ public InputStream getResourceAsStream(String name) {
26372637 * resource is in a package that is not
26382638 * {@linkplain Module#isOpen(String, Module) open} to at least the caller
26392639 * module.
2640- * @throws NullPointerException If {@code name} is {@code null}
26412640 * @since 1.1
26422641 */
26432642 @ CallerSensitive
@@ -3479,7 +3478,7 @@ Map<String, T> enumConstantDirectory() {
34793478 * Casts an object to the class or interface represented
34803479 * by this {@code Class} object.
34813480 *
3482- * @param obj the object to be cast
3481+ * @param obj the object to be cast, may be {@code null}
34833482 * @return the object after casting, or null if obj is null
34843483 *
34853484 * @throws ClassCastException if the object is not
@@ -3534,7 +3533,6 @@ public <U> Class<? extends U> asSubclass(Class<U> clazz) {
35343533 * <p>Note that any annotation returned by this method is a
35353534 * declaration annotation.
35363535 *
3537- * @throws NullPointerException {@inheritDoc}
35383536 * @since 1.5
35393537 */
35403538 @ Override
@@ -3547,7 +3545,6 @@ public <A extends Annotation> A getAnnotation(Class<A> annotationClass) {
35473545
35483546 /**
35493547 * {@inheritDoc}
3550- * @throws NullPointerException {@inheritDoc}
35513548 * @since 1.5
35523549 */
35533550 @ Override
@@ -3560,7 +3557,6 @@ public boolean isAnnotationPresent(Class<? extends Annotation> annotationClass)
35603557 * <p>Note that any annotations returned by this method are
35613558 * declaration annotations.
35623559 *
3563- * @throws NullPointerException {@inheritDoc}
35643560 * @since 1.8
35653561 */
35663562 @ Override
@@ -3590,7 +3586,6 @@ public Annotation[] getAnnotations() {
35903586 * <p>Note that any annotation returned by this method is a
35913587 * declaration annotation.
35923588 *
3593- * @throws NullPointerException {@inheritDoc}
35943589 * @since 1.8
35953590 */
35963591 @ Override
@@ -3606,7 +3601,6 @@ public <A extends Annotation> A getDeclaredAnnotation(Class<A> annotationClass)
36063601 * <p>Note that any annotations returned by this method are
36073602 * declaration annotations.
36083603 *
3609- * @throws NullPointerException {@inheritDoc}
36103604 * @since 1.8
36113605 */
36123606 @ Override
@@ -3837,6 +3831,7 @@ public Class<?> getNestHost() {
38373831 * @since 11
38383832 */
38393833 public boolean isNestmateOf (Class <?> c ) {
3834+ Objects .requireNonNull (c );
38403835 if (this == c ) {
38413836 return true ;
38423837 }
0 commit comments