< prev index next >

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

Print this page

        

*** 289,315 **** boolean throwExceptionIfDenied) { if (caller == MethodHandle.class) { throw new IllegalCallerException(); // should not happen } - Module callerModule = caller.getModule(); - Module declaringModule = declaringClass.getModule(); - - if (callerModule == declaringModule) return true; - if (callerModule == Object.class.getModule()) return true; - if (!declaringModule.isNamed()) return true; - - String pn = declaringClass.getPackageName(); int modifiers; if (this instanceof Executable) { modifiers = ((Executable) this).getModifiers(); } else { modifiers = ((Field) this).getModifiers(); } // class is public and package is exported to caller boolean isClassPublic = Modifier.isPublic(declaringClass.getModifiers()); if (isClassPublic && declaringModule.isExported(pn, callerModule)) { // member is public if (Modifier.isPublic(modifiers)) { logIfExportedForIllegalAccess(caller, declaringClass); return true; --- 289,328 ---- boolean throwExceptionIfDenied) { if (caller == MethodHandle.class) { throw new IllegalCallerException(); // should not happen } int modifiers; if (this instanceof Executable) { modifiers = ((Executable) this).getModifiers(); } else { modifiers = ((Field) this).getModifiers(); } + // Do not allow suppression of access check for inline class's field + if (declaringClass.isInlineClass() && + this instanceof Field + && Modifier.isFinal(modifiers)) { + if (throwExceptionIfDenied) { + String msg = "Unable to make field accessible of inline class " + + declaringClass.getName(); + throw new InaccessibleObjectException(msg); + } else { + return false; + } + } + + Module callerModule = caller.getModule(); + Module declaringModule = declaringClass.getModule(); + + if (callerModule == declaringModule) return true; + if (callerModule == Object.class.getModule()) return true; + if (!declaringModule.isNamed()) return true; + // class is public and package is exported to caller boolean isClassPublic = Modifier.isPublic(declaringClass.getModifiers()); + String pn = declaringClass.getPackageName(); if (isClassPublic && declaringModule.isExported(pn, callerModule)) { // member is public if (Modifier.isPublic(modifiers)) { logIfExportedForIllegalAccess(caller, declaringClass); return true;
< prev index next >