< prev index next >

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

Print this page

163      *     <li> {@code D} is in a package that the module containing {@code D}
164      *     {@link Module#isOpen(String,Module) opens} to at least the module
165      *     containing {@code C}.
166      *     All packages in unnamed and open modules are open to all modules and
167      *     so this method always succeeds when {@code D} is in an unnamed or
168      *     open module. </li>
169      * </ul>
170      *
171      * <p> This method cannot be used to enable access to private members,
172      * members with default (package) access, protected instance members, or
173      * protected constructors when the declaring class is in a different module
174      * to the caller and the package containing the declaring class is not open
175      * to the caller's module. </p>
176      *
177      * <p> This method cannot be used to enable {@linkplain Field#set <em>write</em>}
178      * access to a <em>non-modifiable</em> final field.  The following fields
179      * are non-modifiable:
180      * <ul>
181      * <li>static final fields declared in any class or interface</li>
182      * <li>final fields declared in a {@linkplain Class#isHidden() hidden class}</li>

183      * <li>final fields declared in a {@linkplain Class#isRecord() record}</li>
184      * </ul>
185      * <p> The {@code accessible} flag when {@code true} suppresses Java language access
186      * control checks to only enable {@linkplain Field#get <em>read</em>} access to
187      * these non-modifiable final fields.
188      *
189      * <p> If there is a security manager, its
190      * {@code checkPermission} method is first called with a
191      * {@code ReflectPermission("suppressAccessChecks")} permission.
192      *
193      * @param flag the new value for the {@code accessible} flag
194      * @throws InaccessibleObjectException if access cannot be enabled
195      * @throws SecurityException if the request is denied by the security manager
196      * @see #trySetAccessible
197      * @see java.lang.invoke.MethodHandles#privateLookupIn
198      * @revised 9
199      */
200     @CallerSensitive   // overrides in Method/Field/Constructor are @CS
201     public void setAccessible(boolean flag) {
202         AccessibleObject.checkPermission();

163      *     <li> {@code D} is in a package that the module containing {@code D}
164      *     {@link Module#isOpen(String,Module) opens} to at least the module
165      *     containing {@code C}.
166      *     All packages in unnamed and open modules are open to all modules and
167      *     so this method always succeeds when {@code D} is in an unnamed or
168      *     open module. </li>
169      * </ul>
170      *
171      * <p> This method cannot be used to enable access to private members,
172      * members with default (package) access, protected instance members, or
173      * protected constructors when the declaring class is in a different module
174      * to the caller and the package containing the declaring class is not open
175      * to the caller's module. </p>
176      *
177      * <p> This method cannot be used to enable {@linkplain Field#set <em>write</em>}
178      * access to a <em>non-modifiable</em> final field.  The following fields
179      * are non-modifiable:
180      * <ul>
181      * <li>static final fields declared in any class or interface</li>
182      * <li>final fields declared in a {@linkplain Class#isHidden() hidden class}</li>
183      * <li>fields declared in a {@linkplain Class#isPrimitiveClass() primitive class}</li>
184      * <li>final fields declared in a {@linkplain Class#isRecord() record}</li>
185      * </ul>
186      * <p> The {@code accessible} flag when {@code true} suppresses Java language access
187      * control checks to only enable {@linkplain Field#get <em>read</em>} access to
188      * these non-modifiable final fields.
189      *
190      * <p> If there is a security manager, its
191      * {@code checkPermission} method is first called with a
192      * {@code ReflectPermission("suppressAccessChecks")} permission.
193      *
194      * @param flag the new value for the {@code accessible} flag
195      * @throws InaccessibleObjectException if access cannot be enabled
196      * @throws SecurityException if the request is denied by the security manager
197      * @see #trySetAccessible
198      * @see java.lang.invoke.MethodHandles#privateLookupIn
199      * @revised 9
200      */
201     @CallerSensitive   // overrides in Method/Field/Constructor are @CS
202     public void setAccessible(boolean flag) {
203         AccessibleObject.checkPermission();
< prev index next >