< prev index next >

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

Print this page

171      * with no caller class on the stack to enable access to a {@link Member member}
172      * of {@link Member#getDeclaringClass() declaring class} {@code D} if and only if:
173      * <ul>
174      *     <li> The member is {@code public} and {@code D} is {@code public} in
175      *     a package that the module containing {@code D} {@link
176      *     Module#isExported(String,Module) exports} unconditionally. </li>
177      * </ul>
178      *
179      * <p> This method cannot be used to enable access to private members,
180      * members with default (package) access, protected instance members, or
181      * protected constructors when the declaring class is in a different module
182      * to the caller and the package containing the declaring class is not open
183      * to the caller's module. </p>
184      *
185      * <p> This method cannot be used to enable {@linkplain Field#set <em>write</em>}
186      * access to a <em>non-modifiable</em> final field.  The following fields
187      * are non-modifiable:
188      * <ul>
189      * <li>static final fields declared in any class or interface</li>
190      * <li>final fields declared in a {@linkplain Class#isHidden() hidden class}</li>

191      * <li>final fields declared in a {@linkplain Class#isRecord() record}</li>
192      * </ul>
193      * <p> The {@code accessible} flag when {@code true} suppresses Java language access
194      * control checks to only enable {@linkplain Field#get <em>read</em>} access to
195      * these non-modifiable final fields.
196      *
197      * <p> If there is a security manager, its
198      * {@code checkPermission} method is first called with a
199      * {@code ReflectPermission("suppressAccessChecks")} permission.
200      *
201      * @param flag the new value for the {@code accessible} flag
202      * @throws InaccessibleObjectException if access cannot be enabled
203      * @throws SecurityException if the request is denied by the security manager
204      *
205      * @spec jni/index.html Java Native Interface Specification
206      * @see #trySetAccessible
207      * @see java.lang.invoke.MethodHandles#privateLookupIn
208      */
209     @CallerSensitive   // overrides in Method/Field/Constructor are @CS
210     public void setAccessible(boolean flag) {

171      * with no caller class on the stack to enable access to a {@link Member member}
172      * of {@link Member#getDeclaringClass() declaring class} {@code D} if and only if:
173      * <ul>
174      *     <li> The member is {@code public} and {@code D} is {@code public} in
175      *     a package that the module containing {@code D} {@link
176      *     Module#isExported(String,Module) exports} unconditionally. </li>
177      * </ul>
178      *
179      * <p> This method cannot be used to enable access to private members,
180      * members with default (package) access, protected instance members, or
181      * protected constructors when the declaring class is in a different module
182      * to the caller and the package containing the declaring class is not open
183      * to the caller's module. </p>
184      *
185      * <p> This method cannot be used to enable {@linkplain Field#set <em>write</em>}
186      * access to a <em>non-modifiable</em> final field.  The following fields
187      * are non-modifiable:
188      * <ul>
189      * <li>static final fields declared in any class or interface</li>
190      * <li>final fields declared in a {@linkplain Class#isHidden() hidden class}</li>
191      * <li>fields declared in a {@linkplain Class#isValue() value class}</li>
192      * <li>final fields declared in a {@linkplain Class#isRecord() record}</li>
193      * </ul>
194      * <p> The {@code accessible} flag when {@code true} suppresses Java language access
195      * control checks to only enable {@linkplain Field#get <em>read</em>} access to
196      * these non-modifiable final fields.
197      *
198      * <p> If there is a security manager, its
199      * {@code checkPermission} method is first called with a
200      * {@code ReflectPermission("suppressAccessChecks")} permission.
201      *
202      * @param flag the new value for the {@code accessible} flag
203      * @throws InaccessibleObjectException if access cannot be enabled
204      * @throws SecurityException if the request is denied by the security manager
205      *
206      * @spec jni/index.html Java Native Interface Specification
207      * @see #trySetAccessible
208      * @see java.lang.invoke.MethodHandles#privateLookupIn
209      */
210     @CallerSensitive   // overrides in Method/Field/Constructor are @CS
211     public void setAccessible(boolean flag) {
< prev index next >