if (callerModule == declaringModule) returntrue; if (callerModule == Object.class.getModule()) returntrue; if (!declaringModule.isNamed()) returntrue;
Stringpn= declaringClass.getPackageName(); int modifiers; if (thisinstanceof Executable) { modifiers = ((Executable) this).getModifiers(); } else { modifiers = ((Field) this).getModifiers(); }
// class is public and package is exported to caller booleanisClassPublic= Modifier.isPublic(declaringClass.getModifiers()); if (isClassPublic && declaringModule.isExported(pn, callerModule)) { // member is public if (Modifier.isPublic(modifiers)) { returntrue; }
// member is protected-static if (Modifier.isProtected(modifiers) && Modifier.isStatic(modifiers) && isSubclassOf(caller, declaringClass)) { returntrue; } }
// package is open to caller if (declaringModule.isOpen(pn, callerModule)) { returntrue; }
if (throwExceptionIfDenied) { // not accessible Stringmsg="Unable to make "; if (thisinstanceof Field) msg += "field "; msg += this + " accessible: " + declaringModule + " does not \""; if (isClassPublic && Modifier.isPublic(modifiers)) msg += "exports"; else msg += "opens"; msg += " " + pn + "\" to " + callerModule; InaccessibleObjectExceptione=newInaccessibleObjectException(msg); if (printStackTraceWhenAccessFails()) { e.printStackTrace(System.err); } throw e; } returnfalse; }