< prev index next >

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

Print this page




 388             caller = Reflection.getCallerClass();
 389             if (loader == null) {
 390                 ClassLoader ccl = ClassLoader.getClassLoader(caller);
 391                 if (ccl != null) {
 392                     sm.checkPermission(
 393                         SecurityConstants.GET_CLASSLOADER_PERMISSION);
 394                 }
 395             }
 396         }
 397         return forName0(name, initialize, loader, caller);
 398     }
 399 
 400     /** Called after security check for system loader access checks have been made. */
 401     private static native Class<?> forName0(String name, boolean initialize,
 402                                             ClassLoader loader,
 403                                             Class<?> caller)
 404         throws ClassNotFoundException;
 405 
 406 
 407     /**
 408      * Returns the {@code Class} with the given <a href="ClassLoader.html#name">
 409      * binary name</a> in the given module.
 410      *
 411      * <p> This method attempts to locate, load, and link the class or interface.
 412      * It does not run the class initializer.  If the class is not found, this
 413      * method returns {@code null}. </p>
 414      *
 415      * <p> If the class loader of the given module defines other modules and
 416      * the given name is a class defined in a different module, this method
 417      * returns {@code null} after the class is loaded. </p>
 418      *
 419      * <p> This method does not check whether the requested class is
 420      * accessible to its caller. </p>
 421      *
 422      * @apiNote
 423      * This method returns {@code null} on failure rather than
 424      * throwing a {@link ClassNotFoundException}, as is done by
 425      * the {@link #forName(String, boolean, ClassLoader)} method.
 426      * The security check is a stack-based permission check if the caller
 427      * loads a class in another module.
 428      *
 429      * @param  module   A module
 430      * @param  name     The <a href="ClassLoader.html#name">binary name</a>
 431      *                  of the class
 432      * @return {@code Class} object of the given name defined in the given module;
 433      *         {@code null} if not found.
 434      *
 435      * @throws NullPointerException if the given module or name is {@code null}
 436      *
 437      * @throws LinkageError if the linkage fails
 438      *
 439      * @throws SecurityException
 440      *         <ul>
 441      *         <li> if the caller is not the specified module and
 442      *         {@code RuntimePermission("getClassLoader")} permission is denied; or</li>
 443      *         <li> access to the module content is denied. For example,
 444      *         permission check will be performed when a class loader calls
 445      *         {@link ModuleReader#open(String)} to read the bytes of a class file
 446      *         in a module.</li>
 447      *         </ul>
 448      *
 449      * @since 9
 450      * @spec JPMS




 388             caller = Reflection.getCallerClass();
 389             if (loader == null) {
 390                 ClassLoader ccl = ClassLoader.getClassLoader(caller);
 391                 if (ccl != null) {
 392                     sm.checkPermission(
 393                         SecurityConstants.GET_CLASSLOADER_PERMISSION);
 394                 }
 395             }
 396         }
 397         return forName0(name, initialize, loader, caller);
 398     }
 399 
 400     /** Called after security check for system loader access checks have been made. */
 401     private static native Class<?> forName0(String name, boolean initialize,
 402                                             ClassLoader loader,
 403                                             Class<?> caller)
 404         throws ClassNotFoundException;
 405 
 406 
 407     /**
 408      * Returns the {@code Class} with the given <a href="ClassLoader.html#binary-name">
 409      * binary name</a> in the given module.
 410      *
 411      * <p> This method attempts to locate, load, and link the class or interface.
 412      * It does not run the class initializer.  If the class is not found, this
 413      * method returns {@code null}. </p>
 414      *
 415      * <p> If the class loader of the given module defines other modules and
 416      * the given name is a class defined in a different module, this method
 417      * returns {@code null} after the class is loaded. </p>
 418      *
 419      * <p> This method does not check whether the requested class is
 420      * accessible to its caller. </p>
 421      *
 422      * @apiNote
 423      * This method returns {@code null} on failure rather than
 424      * throwing a {@link ClassNotFoundException}, as is done by
 425      * the {@link #forName(String, boolean, ClassLoader)} method.
 426      * The security check is a stack-based permission check if the caller
 427      * loads a class in another module.
 428      *
 429      * @param  module   A module
 430      * @param  name     The <a href="ClassLoader.html#binary-name">binary name</a>
 431      *                  of the class
 432      * @return {@code Class} object of the given name defined in the given module;
 433      *         {@code null} if not found.
 434      *
 435      * @throws NullPointerException if the given module or name is {@code null}
 436      *
 437      * @throws LinkageError if the linkage fails
 438      *
 439      * @throws SecurityException
 440      *         <ul>
 441      *         <li> if the caller is not the specified module and
 442      *         {@code RuntimePermission("getClassLoader")} permission is denied; or</li>
 443      *         <li> access to the module content is denied. For example,
 444      *         permission check will be performed when a class loader calls
 445      *         {@link ModuleReader#open(String)} to read the bytes of a class file
 446      *         in a module.</li>
 447      *         </ul>
 448      *
 449      * @since 9
 450      * @spec JPMS


< prev index next >