< prev index next >

src/java.base/share/classes/java/lang/reflect/Constructor.java

Print this page
rev 55117 : 8223350: [lworld] Use inline classes instead of value classes


 165      * <p> A {@code SecurityException} is also thrown if this object is a
 166      * {@code Constructor} object for the class {@code Class} and {@code flag}
 167      * is true. </p>
 168      *
 169      * @param flag {@inheritDoc}
 170      *
 171      * @throws InaccessibleObjectException {@inheritDoc}
 172      * @throws SecurityException if the request is denied by the security manager
 173      *         or this is a constructor for {@code java.lang.Class}
 174      *
 175      * @spec JPMS
 176      */
 177     @Override
 178     @CallerSensitive
 179     public void setAccessible(boolean flag) {
 180         AccessibleObject.checkPermission();
 181 
 182         if (flag) {
 183             if (clazz.isValue()) {
 184                 throw new InaccessibleObjectException(
 185                     "Unable to make a value class constructor \"" + this + "\" accessible");
 186             }
 187             checkCanSetAccessible(Reflection.getCallerClass());
 188         }
 189         setAccessible0(flag);
 190     }
 191 
 192     @Override
 193     void checkCanSetAccessible(Class<?> caller) {
 194         checkCanSetAccessible(caller, clazz);
 195         if (clazz == Class.class) {
 196             // can we change this to InaccessibleObjectException?
 197             throw new SecurityException("Cannot make a java.lang.Class"
 198                                         + " constructor accessible");
 199         }
 200     }
 201 
 202     @Override
 203     boolean hasGenericInformation() {
 204         return (getSignature() != null);
 205     }


 468      *              conversion for primitive arguments fails; or if,
 469      *              after possible unwrapping, a parameter value
 470      *              cannot be converted to the corresponding formal
 471      *              parameter type by a method invocation conversion; if
 472      *              this constructor pertains to an enum type.
 473      * @exception InstantiationException    if the class that declares the
 474      *              underlying constructor represents an abstract class.
 475      * @exception InvocationTargetException if the underlying constructor
 476      *              throws an exception.
 477      * @exception ExceptionInInitializerError if the initialization provoked
 478      *              by this method fails.
 479      */
 480     @CallerSensitive
 481     @ForceInline // to ensure Reflection.getCallerClass optimization
 482     public T newInstance(Object ... initargs)
 483         throws InstantiationException, IllegalAccessException,
 484                IllegalArgumentException, InvocationTargetException
 485     {
 486         if (clazz.isValue()) {
 487             throw new IllegalAccessException(
 488                 "cannot create new instance of value class " + clazz.getName());
 489         }
 490         Class<?> caller = override ? null : Reflection.getCallerClass();
 491         return newInstanceWithCaller(initargs, !override, caller);
 492     }
 493 
 494     /* package-private */
 495     T newInstanceWithCaller(Object[] args, boolean checkAccess, Class<?> caller)
 496         throws InstantiationException, IllegalAccessException,
 497                InvocationTargetException
 498     {
 499         if (checkAccess)
 500             checkAccess(caller, clazz, clazz, modifiers);
 501 
 502         if ((clazz.getModifiers() & Modifier.ENUM) != 0)
 503             throw new IllegalArgumentException("Cannot reflectively create enum objects");
 504 
 505         ConstructorAccessor ca = constructorAccessor;   // read volatile
 506         if (ca == null) {
 507             ca = acquireConstructorAccessor();
 508         }




 165      * <p> A {@code SecurityException} is also thrown if this object is a
 166      * {@code Constructor} object for the class {@code Class} and {@code flag}
 167      * is true. </p>
 168      *
 169      * @param flag {@inheritDoc}
 170      *
 171      * @throws InaccessibleObjectException {@inheritDoc}
 172      * @throws SecurityException if the request is denied by the security manager
 173      *         or this is a constructor for {@code java.lang.Class}
 174      *
 175      * @spec JPMS
 176      */
 177     @Override
 178     @CallerSensitive
 179     public void setAccessible(boolean flag) {
 180         AccessibleObject.checkPermission();
 181 
 182         if (flag) {
 183             if (clazz.isValue()) {
 184                 throw new InaccessibleObjectException(
 185                     "Unable to make an inline class constructor \"" + this + "\" accessible");
 186             }
 187             checkCanSetAccessible(Reflection.getCallerClass());
 188         }
 189         setAccessible0(flag);
 190     }
 191 
 192     @Override
 193     void checkCanSetAccessible(Class<?> caller) {
 194         checkCanSetAccessible(caller, clazz);
 195         if (clazz == Class.class) {
 196             // can we change this to InaccessibleObjectException?
 197             throw new SecurityException("Cannot make a java.lang.Class"
 198                                         + " constructor accessible");
 199         }
 200     }
 201 
 202     @Override
 203     boolean hasGenericInformation() {
 204         return (getSignature() != null);
 205     }


 468      *              conversion for primitive arguments fails; or if,
 469      *              after possible unwrapping, a parameter value
 470      *              cannot be converted to the corresponding formal
 471      *              parameter type by a method invocation conversion; if
 472      *              this constructor pertains to an enum type.
 473      * @exception InstantiationException    if the class that declares the
 474      *              underlying constructor represents an abstract class.
 475      * @exception InvocationTargetException if the underlying constructor
 476      *              throws an exception.
 477      * @exception ExceptionInInitializerError if the initialization provoked
 478      *              by this method fails.
 479      */
 480     @CallerSensitive
 481     @ForceInline // to ensure Reflection.getCallerClass optimization
 482     public T newInstance(Object ... initargs)
 483         throws InstantiationException, IllegalAccessException,
 484                IllegalArgumentException, InvocationTargetException
 485     {
 486         if (clazz.isValue()) {
 487             throw new IllegalAccessException(
 488                 "cannot create new instance of an inline class " + clazz.getName());
 489         }
 490         Class<?> caller = override ? null : Reflection.getCallerClass();
 491         return newInstanceWithCaller(initargs, !override, caller);
 492     }
 493 
 494     /* package-private */
 495     T newInstanceWithCaller(Object[] args, boolean checkAccess, Class<?> caller)
 496         throws InstantiationException, IllegalAccessException,
 497                InvocationTargetException
 498     {
 499         if (checkAccess)
 500             checkAccess(caller, clazz, clazz, modifiers);
 501 
 502         if ((clazz.getModifiers() & Modifier.ENUM) != 0)
 503             throw new IllegalArgumentException("Cannot reflectively create enum objects");
 504 
 505         ConstructorAccessor ca = constructorAccessor;   // read volatile
 506         if (ca == null) {
 507             ca = acquireConstructorAccessor();
 508         }


< prev index next >