163 * {@inheritDoc}
164 *
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.isInlineClass()) {
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 }
206
465 * @exception IllegalArgumentException if the number of actual
466 * and formal parameters differ; if an unwrapping
467 * conversion for primitive arguments fails; or if,
468 * after possible unwrapping, a parameter value
469 * cannot be converted to the corresponding formal
470 * parameter type by a method invocation conversion; if
471 * this constructor pertains to an enum type.
472 * @exception InstantiationException if the class that declares the
473 * underlying constructor represents an abstract class.
474 * @exception InvocationTargetException if the underlying constructor
475 * throws an exception.
476 * @exception ExceptionInInitializerError if the initialization provoked
477 * by this method fails.
478 */
479 @CallerSensitive
480 @ForceInline // to ensure Reflection.getCallerClass optimization
481 public T newInstance(Object ... initargs)
482 throws InstantiationException, IllegalAccessException,
483 IllegalArgumentException, InvocationTargetException
484 {
485 if (clazz.isInlineClass()) {
486 throw new IllegalAccessException(
487 "cannot create new instance of an inline class " + clazz.getName());
488 }
489 Class<?> caller = override ? null : Reflection.getCallerClass();
490 return newInstanceWithCaller(initargs, !override, caller);
491 }
492
493 /* package-private */
494 T newInstanceWithCaller(Object[] args, boolean checkAccess, Class<?> caller)
495 throws InstantiationException, IllegalAccessException,
496 InvocationTargetException
497 {
498 if (checkAccess)
499 checkAccess(caller, clazz, clazz, modifiers);
500
501 if ((clazz.getModifiers() & Modifier.ENUM) != 0)
502 throw new IllegalArgumentException("Cannot reflectively create enum objects");
503
504 ConstructorAccessor ca = constructorAccessor; // read volatile
505 if (ca == null) {
506 ca = acquireConstructorAccessor();
507 }
508 @SuppressWarnings("unchecked")
|
163 * {@inheritDoc}
164 *
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 checkCanSetAccessible(Reflection.getCallerClass());
184 }
185 setAccessible0(flag);
186 }
187
188 @Override
189 void checkCanSetAccessible(Class<?> caller) {
190 checkCanSetAccessible(caller, clazz);
191 if (clazz == Class.class) {
192 // can we change this to InaccessibleObjectException?
193 throw new SecurityException("Cannot make a java.lang.Class"
194 + " constructor accessible");
195 }
196 }
197
198 @Override
199 boolean hasGenericInformation() {
200 return (getSignature() != null);
201 }
202
461 * @exception IllegalArgumentException if the number of actual
462 * and formal parameters differ; if an unwrapping
463 * conversion for primitive arguments fails; or if,
464 * after possible unwrapping, a parameter value
465 * cannot be converted to the corresponding formal
466 * parameter type by a method invocation conversion; if
467 * this constructor pertains to an enum type.
468 * @exception InstantiationException if the class that declares the
469 * underlying constructor represents an abstract class.
470 * @exception InvocationTargetException if the underlying constructor
471 * throws an exception.
472 * @exception ExceptionInInitializerError if the initialization provoked
473 * by this method fails.
474 */
475 @CallerSensitive
476 @ForceInline // to ensure Reflection.getCallerClass optimization
477 public T newInstance(Object ... initargs)
478 throws InstantiationException, IllegalAccessException,
479 IllegalArgumentException, InvocationTargetException
480 {
481 Class<?> caller = override ? null : Reflection.getCallerClass();
482 return newInstanceWithCaller(initargs, !override, caller);
483 }
484
485 /* package-private */
486 T newInstanceWithCaller(Object[] args, boolean checkAccess, Class<?> caller)
487 throws InstantiationException, IllegalAccessException,
488 InvocationTargetException
489 {
490 if (checkAccess)
491 checkAccess(caller, clazz, clazz, modifiers);
492
493 if ((clazz.getModifiers() & Modifier.ENUM) != 0)
494 throw new IllegalArgumentException("Cannot reflectively create enum objects");
495
496 ConstructorAccessor ca = constructorAccessor; // read volatile
497 if (ca == null) {
498 ca = acquireConstructorAccessor();
499 }
500 @SuppressWarnings("unchecked")
|