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