equal
deleted
inserted
replaced
390 * {@code null}, and the caller does not have the |
390 * {@code null}, and the caller does not have the |
391 * {@link RuntimePermission}{@code ("getClassLoader")} |
391 * {@link RuntimePermission}{@code ("getClassLoader")} |
392 * |
392 * |
393 * @see java.lang.Class#forName(String) |
393 * @see java.lang.Class#forName(String) |
394 * @see java.lang.ClassLoader |
394 * @see java.lang.ClassLoader |
|
395 * |
|
396 * @jls 12.2 Loading of Classes and Interfaces |
|
397 * @jls 12.3 Linking of Classes and Interfaces |
|
398 * @jls 12.4 Initialization of Classes and Interfaces |
395 * @since 1.2 |
399 * @since 1.2 |
396 */ |
400 */ |
397 @CallerSensitive |
401 @CallerSensitive |
398 public static Class<?> forName(String name, boolean initialize, |
402 public static Class<?> forName(String name, boolean initialize, |
399 ClassLoader loader) |
403 ClassLoader loader) |
436 * returns {@code null} after the class is loaded. </p> |
440 * returns {@code null} after the class is loaded. </p> |
437 * |
441 * |
438 * <p> This method does not check whether the requested class is |
442 * <p> This method does not check whether the requested class is |
439 * accessible to its caller. </p> |
443 * accessible to its caller. </p> |
440 * |
444 * |
|
445 * <p> Note that this method throws errors related to loading and linking as |
|
446 * specified in Sections 12.2 and 12.3 of <em>The Java Language |
|
447 * Specification</em>. |
|
448 * |
441 * @apiNote |
449 * @apiNote |
442 * This method returns {@code null} on failure rather than |
450 * This method returns {@code null} on failure rather than |
443 * throwing a {@link ClassNotFoundException}, as is done by |
451 * throwing a {@link ClassNotFoundException}, as is done by |
444 * the {@link #forName(String, boolean, ClassLoader)} method. |
452 * the {@link #forName(String, boolean, ClassLoader)} method. |
445 * The security check is a stack-based permission check if the caller |
453 * The security check is a stack-based permission check if the caller |
463 * permission check will be performed when a class loader calls |
471 * permission check will be performed when a class loader calls |
464 * {@link ModuleReader#open(String)} to read the bytes of a class file |
472 * {@link ModuleReader#open(String)} to read the bytes of a class file |
465 * in a module.</li> |
473 * in a module.</li> |
466 * </ul> |
474 * </ul> |
467 * |
475 * |
|
476 * @jls 12.2 Loading of Classes and Interfaces |
|
477 * @jls 12.3 Linking of Classes and Interfaces |
468 * @since 9 |
478 * @since 9 |
469 * @spec JPMS |
479 * @spec JPMS |
470 */ |
480 */ |
471 @CallerSensitive |
481 @CallerSensitive |
472 public static Class<?> forName(Module module, String name) { |
482 public static Class<?> forName(Module module, String name) { |
486 cl = AccessController.doPrivileged(pa); |
496 cl = AccessController.doPrivileged(pa); |
487 } else { |
497 } else { |
488 cl = module.getClassLoader(); |
498 cl = module.getClassLoader(); |
489 } |
499 } |
490 |
500 |
|
501 Class<?> ret; |
491 if (cl != null) { |
502 if (cl != null) { |
492 return cl.loadClass(module, name); |
503 ret = cl.loadClass(module, name); |
493 } else { |
504 } else { |
494 return BootLoader.loadClass(module, name); |
505 ret = BootLoader.loadClass(module, name); |
495 } |
506 } |
496 } |
507 if (ret != null) { |
|
508 // The loaded class should also be linked |
|
509 linkClass(ret); |
|
510 } |
|
511 return ret; |
|
512 } |
|
513 |
|
514 private static native void linkClass(Class<?> c); |
497 |
515 |
498 /** |
516 /** |
499 * Creates a new instance of the class represented by this {@code Class} |
517 * Creates a new instance of the class represented by this {@code Class} |
500 * object. The class is instantiated as if by a {@code new} |
518 * object. The class is instantiated as if by a {@code new} |
501 * expression with an empty argument list. The class is initialized if it |
519 * expression with an empty argument list. The class is initialized if it |