< prev index next >

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

Print this page




 151         Constructor<T> res = new Constructor<>(clazz,
 152                                                parameterTypes,
 153                                                exceptionTypes, modifiers, slot,
 154                                                signature,
 155                                                annotations,
 156                                                parameterAnnotations);
 157         res.root = this;
 158         // Might as well eagerly propagate this if already present
 159         res.constructorAccessor = constructorAccessor;
 160         return res;
 161     }
 162 
 163     /**
 164      * {@inheritDoc}
 165      *
 166      * <p> A {@code SecurityException} is also thrown if this object is a
 167      * {@code Constructor} object for the class {@code Class} and {@code flag}
 168      * is true. </p>
 169      *
 170      * @param flag {@inheritDoc}







 171      */
 172     @Override
 173     @CallerSensitive
 174     public void setAccessible(boolean flag) {
 175         AccessibleObject.checkPermission();
 176         if (flag) {
 177             checkCanSetAccessible(Reflection.getCallerClass());
 178         }
 179         setAccessible0(flag);
 180     }
 181 
 182     @Override
 183     void checkCanSetAccessible(Class<?> caller) {
 184         checkCanSetAccessible(caller, clazz);
 185         if (clazz == Class.class) {
 186             // can we change this to InaccessibleObjectException?
 187             throw new SecurityException("Cannot make a java.lang.Class"
 188                                         + " constructor accessible");
 189         }
 190     }




 151         Constructor<T> res = new Constructor<>(clazz,
 152                                                parameterTypes,
 153                                                exceptionTypes, modifiers, slot,
 154                                                signature,
 155                                                annotations,
 156                                                parameterAnnotations);
 157         res.root = this;
 158         // Might as well eagerly propagate this if already present
 159         res.constructorAccessor = constructorAccessor;
 160         return res;
 161     }
 162 
 163     /**
 164      * {@inheritDoc}
 165      *
 166      * <p> A {@code SecurityException} is also thrown if this object is a
 167      * {@code Constructor} object for the class {@code Class} and {@code flag}
 168      * is true. </p>
 169      *
 170      * @param flag {@inheritDoc}
 171      *
 172      * @throws InaccessibleObjectException {@inheritDoc}
 173      * @throws SecurityException if the request is denied by the security manager
 174      *         or this is a constructor for {@code java.lang.Class}
 175      *
 176      * @since 9
 177      * @spec JPMS
 178      */
 179     @Override
 180     @CallerSensitive
 181     public void setAccessible(boolean flag) {
 182         AccessibleObject.checkPermission();
 183         if (flag) {
 184             checkCanSetAccessible(Reflection.getCallerClass());
 185         }
 186         setAccessible0(flag);
 187     }
 188 
 189     @Override
 190     void checkCanSetAccessible(Class<?> caller) {
 191         checkCanSetAccessible(caller, clazz);
 192         if (clazz == Class.class) {
 193             // can we change this to InaccessibleObjectException?
 194             throw new SecurityException("Cannot make a java.lang.Class"
 195                                         + " constructor accessible");
 196         }
 197     }


< prev index next >