< prev index next >

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

Print this page

149      * with no caller class on the stack to enable access to a {@link Member member}
150      * of {@link Member#getDeclaringClass() declaring class} {@code D} if and only if:
151      * <ul>
152      *     <li> The member is {@code public} and {@code D} is {@code public} in
153      *     a package that the module containing {@code D} {@link
154      *     Module#isExported(String,Module) exports} unconditionally. </li>
155      * </ul>
156      *
157      * <p> This method cannot be used to enable access to private members,
158      * members with default (package) access, protected instance members, or
159      * protected constructors when the declaring class is in a different module
160      * to the caller and the package containing the declaring class is not open
161      * to the caller's module. </p>
162      *
163      * <p> This method cannot be used to enable {@linkplain Field#set <em>write</em>}
164      * access to a <em>non-modifiable</em> final field.  The following fields
165      * are non-modifiable:
166      * <ul>
167      * <li>static final fields declared in any class or interface</li>
168      * <li>final fields declared in a {@linkplain Class#isHidden() hidden class}</li>

169      * <li>final fields declared in a {@linkplain Class#isRecord() record}</li>
170      * </ul>
171      * <p> The {@code accessible} flag when {@code true} suppresses Java language access
172      * control checks to only enable {@linkplain Field#get <em>read</em>} access to
173      * these non-modifiable final fields.
174      *
175      * @param flag the new value for the {@code accessible} flag
176      * @throws InaccessibleObjectException if access cannot be enabled
177      *
178      * @spec jni/index.html Java Native Interface Specification
179      * @see #trySetAccessible
180      * @see java.lang.invoke.MethodHandles#privateLookupIn
181      */
182     @CallerSensitive   // overrides in Method/Field/Constructor are @CS
183     public void setAccessible(boolean flag) {
184         setAccessible0(flag);
185     }
186 
187     /**
188      * Sets the accessible flag and returns the new value

149      * with no caller class on the stack to enable access to a {@link Member member}
150      * of {@link Member#getDeclaringClass() declaring class} {@code D} if and only if:
151      * <ul>
152      *     <li> The member is {@code public} and {@code D} is {@code public} in
153      *     a package that the module containing {@code D} {@link
154      *     Module#isExported(String,Module) exports} unconditionally. </li>
155      * </ul>
156      *
157      * <p> This method cannot be used to enable access to private members,
158      * members with default (package) access, protected instance members, or
159      * protected constructors when the declaring class is in a different module
160      * to the caller and the package containing the declaring class is not open
161      * to the caller's module. </p>
162      *
163      * <p> This method cannot be used to enable {@linkplain Field#set <em>write</em>}
164      * access to a <em>non-modifiable</em> final field.  The following fields
165      * are non-modifiable:
166      * <ul>
167      * <li>static final fields declared in any class or interface</li>
168      * <li>final fields declared in a {@linkplain Class#isHidden() hidden class}</li>
169      * <li>fields declared in a {@linkplain Class#isValue() value class}</li>
170      * <li>final fields declared in a {@linkplain Class#isRecord() record}</li>
171      * </ul>
172      * <p> The {@code accessible} flag when {@code true} suppresses Java language access
173      * control checks to only enable {@linkplain Field#get <em>read</em>} access to
174      * these non-modifiable final fields.
175      *
176      * @param flag the new value for the {@code accessible} flag
177      * @throws InaccessibleObjectException if access cannot be enabled
178      *
179      * @spec jni/index.html Java Native Interface Specification
180      * @see #trySetAccessible
181      * @see java.lang.invoke.MethodHandles#privateLookupIn
182      */
183     @CallerSensitive   // overrides in Method/Field/Constructor are @CS
184     public void setAccessible(boolean flag) {
185         setAccessible0(flag);
186     }
187 
188     /**
189      * Sets the accessible flag and returns the new value
< prev index next >