281 }
282
283 final void checkCanSetAccessible(Class<?> caller, Class<?> declaringClass) {
284 checkCanSetAccessible(caller, declaringClass, true);
285 }
286
287 private boolean checkCanSetAccessible(Class<?> caller,
288 Class<?> declaringClass,
289 boolean throwExceptionIfDenied) {
290 if (caller == MethodHandle.class) {
291 throw new IllegalCallerException(); // should not happen
292 }
293
294 int modifiers;
295 if (this instanceof Executable) {
296 modifiers = ((Executable) this).getModifiers();
297 } else {
298 modifiers = ((Field) this).getModifiers();
299 }
300
301 // does not allow to suppress access check for Value class's
302 // constructor or field
303 if (declaringClass.isInlineClass()) {
304 if (this instanceof Constructor) return false;
305 if (this instanceof Field && Modifier.isFinal(modifiers)) return false;
306 }
307
308 Module callerModule = caller.getModule();
309 Module declaringModule = declaringClass.getModule();
310
311 if (callerModule == declaringModule) return true;
312 if (callerModule == Object.class.getModule()) return true;
313 if (!declaringModule.isNamed()) return true;
314
315 // class is public and package is exported to caller
316 boolean isClassPublic = Modifier.isPublic(declaringClass.getModifiers());
317 String pn = declaringClass.getPackageName();
318 if (isClassPublic && declaringModule.isExported(pn, callerModule)) {
319 // member is public
320 if (Modifier.isPublic(modifiers)) {
321 logIfExportedForIllegalAccess(caller, declaringClass);
322 return true;
323 }
324
|
281 }
282
283 final void checkCanSetAccessible(Class<?> caller, Class<?> declaringClass) {
284 checkCanSetAccessible(caller, declaringClass, true);
285 }
286
287 private boolean checkCanSetAccessible(Class<?> caller,
288 Class<?> declaringClass,
289 boolean throwExceptionIfDenied) {
290 if (caller == MethodHandle.class) {
291 throw new IllegalCallerException(); // should not happen
292 }
293
294 int modifiers;
295 if (this instanceof Executable) {
296 modifiers = ((Executable) this).getModifiers();
297 } else {
298 modifiers = ((Field) this).getModifiers();
299 }
300
301 // Do not allow suppression of access check for inline class's field
302 if (declaringClass.isInlineClass()) {
303 if (this instanceof Field && Modifier.isFinal(modifiers)) return false;
304 }
305
306 Module callerModule = caller.getModule();
307 Module declaringModule = declaringClass.getModule();
308
309 if (callerModule == declaringModule) return true;
310 if (callerModule == Object.class.getModule()) return true;
311 if (!declaringModule.isNamed()) return true;
312
313 // class is public and package is exported to caller
314 boolean isClassPublic = Modifier.isPublic(declaringClass.getModifiers());
315 String pn = declaringClass.getPackageName();
316 if (isClassPublic && declaringModule.isExported(pn, callerModule)) {
317 // member is public
318 if (Modifier.isPublic(modifiers)) {
319 logIfExportedForIllegalAccess(caller, declaringClass);
320 return true;
321 }
322
|