< prev index next >

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

Print this page
rev 55690 : 8223349: [lworld] Reflection support on static <init> factory methods for inline types
Reviewed-by: jrose


 614      * @throws  InstantiationException
 615      *          if this {@code Class} represents an abstract class,
 616      *          an interface, an array class, a primitive type, or void;
 617      *          or if the class has no nullary constructor;
 618      *          or if the instantiation fails for some other reason.
 619      * @throws  ExceptionInInitializerError if the initialization
 620      *          provoked by this method fails.
 621      * @throws  SecurityException
 622      *          If a security manager, <i>s</i>, is present and
 623      *          the caller's class loader is not the same as or an
 624      *          ancestor of the class loader for the current class and
 625      *          invocation of {@link SecurityManager#checkPackageAccess
 626      *          s.checkPackageAccess()} denies access to the package
 627      *          of this class.
 628      */
 629     @CallerSensitive
 630     @Deprecated(since="9")
 631     public T newInstance()
 632         throws InstantiationException, IllegalAccessException
 633     {
 634         if (this.isInlineClass()) {
 635             throw new IllegalAccessException(
 636                 "cannot create new instance of an inline class " + this.getName());
 637         }
 638 
 639         SecurityManager sm = System.getSecurityManager();
 640         if (sm != null) {
 641             checkMemberAccess(sm, Member.PUBLIC, Reflection.getCallerClass(), false);
 642         }
 643 
 644         // Constructor lookup
 645         Constructor<T> tmpConstructor = cachedConstructor;
 646         if (tmpConstructor == null) {
 647             if (this == Class.class) {
 648                 throw new IllegalAccessException(
 649                     "Can not call newInstance() on the Class for java.lang.Class"
 650                 );
 651             }
 652             try {
 653                 Class<?>[] empty = {};
 654                 final Constructor<T> c = getReflectionFactory().copyConstructor(
 655                     getConstructor0(empty, Member.DECLARED));
 656                 // Disable accessibility checks on the constructor
 657                 // access check is done with the true caller
 658                 java.security.AccessController.doPrivileged(




 614      * @throws  InstantiationException
 615      *          if this {@code Class} represents an abstract class,
 616      *          an interface, an array class, a primitive type, or void;
 617      *          or if the class has no nullary constructor;
 618      *          or if the instantiation fails for some other reason.
 619      * @throws  ExceptionInInitializerError if the initialization
 620      *          provoked by this method fails.
 621      * @throws  SecurityException
 622      *          If a security manager, <i>s</i>, is present and
 623      *          the caller's class loader is not the same as or an
 624      *          ancestor of the class loader for the current class and
 625      *          invocation of {@link SecurityManager#checkPackageAccess
 626      *          s.checkPackageAccess()} denies access to the package
 627      *          of this class.
 628      */
 629     @CallerSensitive
 630     @Deprecated(since="9")
 631     public T newInstance()
 632         throws InstantiationException, IllegalAccessException
 633     {





 634         SecurityManager sm = System.getSecurityManager();
 635         if (sm != null) {
 636             checkMemberAccess(sm, Member.PUBLIC, Reflection.getCallerClass(), false);
 637         }
 638 
 639         // Constructor lookup
 640         Constructor<T> tmpConstructor = cachedConstructor;
 641         if (tmpConstructor == null) {
 642             if (this == Class.class) {
 643                 throw new IllegalAccessException(
 644                     "Can not call newInstance() on the Class for java.lang.Class"
 645                 );
 646             }
 647             try {
 648                 Class<?>[] empty = {};
 649                 final Constructor<T> c = getReflectionFactory().copyConstructor(
 650                     getConstructor0(empty, Member.DECLARED));
 651                 // Disable accessibility checks on the constructor
 652                 // access check is done with the true caller
 653                 java.security.AccessController.doPrivileged(


< prev index next >