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 |
|
399 * @since 1.2 |
395 * @since 1.2 |
400 */ |
396 */ |
401 @CallerSensitive |
397 @CallerSensitive |
402 public static Class<?> forName(String name, boolean initialize, |
398 public static Class<?> forName(String name, boolean initialize, |
403 ClassLoader loader) |
399 ClassLoader loader) |
440 * returns {@code null} after the class is loaded. </p> |
436 * returns {@code null} after the class is loaded. </p> |
441 * |
437 * |
442 * <p> This method does not check whether the requested class is |
438 * <p> This method does not check whether the requested class is |
443 * accessible to its caller. </p> |
439 * accessible to its caller. </p> |
444 * |
440 * |
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 * |
|
449 * @apiNote |
441 * @apiNote |
450 * This method returns {@code null} on failure rather than |
442 * This method returns {@code null} on failure rather than |
451 * throwing a {@link ClassNotFoundException}, as is done by |
443 * throwing a {@link ClassNotFoundException}, as is done by |
452 * the {@link #forName(String, boolean, ClassLoader)} method. |
444 * the {@link #forName(String, boolean, ClassLoader)} method. |
453 * The security check is a stack-based permission check if the caller |
445 * The security check is a stack-based permission check if the caller |
471 * permission check will be performed when a class loader calls |
463 * permission check will be performed when a class loader calls |
472 * {@link ModuleReader#open(String)} to read the bytes of a class file |
464 * {@link ModuleReader#open(String)} to read the bytes of a class file |
473 * in a module.</li> |
465 * in a module.</li> |
474 * </ul> |
466 * </ul> |
475 * |
467 * |
476 * @jls 12.2 Loading of Classes and Interfaces |
|
477 * @jls 12.3 Linking of Classes and Interfaces |
|
478 * @since 9 |
468 * @since 9 |
479 * @spec JPMS |
469 * @spec JPMS |
480 */ |
470 */ |
481 @CallerSensitive |
471 @CallerSensitive |
482 public static Class<?> forName(Module module, String name) { |
472 public static Class<?> forName(Module module, String name) { |
496 cl = AccessController.doPrivileged(pa); |
486 cl = AccessController.doPrivileged(pa); |
497 } else { |
487 } else { |
498 cl = module.getClassLoader(); |
488 cl = module.getClassLoader(); |
499 } |
489 } |
500 |
490 |
501 Class<?> ret; |
|
502 if (cl != null) { |
491 if (cl != null) { |
503 ret = cl.loadClass(module, name); |
492 return cl.loadClass(module, name); |
504 } else { |
493 } else { |
505 ret = BootLoader.loadClass(module, name); |
494 return BootLoader.loadClass(module, name); |
506 } |
495 } |
507 if (ret != null) { |
496 } |
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); |
|
515 |
497 |
516 /** |
498 /** |
517 * Creates a new instance of the class represented by this {@code Class} |
499 * Creates a new instance of the class represented by this {@code Class} |
518 * object. The class is instantiated as if by a {@code new} |
500 * object. The class is instantiated as if by a {@code new} |
519 * expression with an empty argument list. The class is initialized if it |
501 * expression with an empty argument list. The class is initialized if it |