Skip to content

Commit

Permalink
Restore legacy Lookup.checkClassModuleVisibility() for legacy Java 9 …
Browse files Browse the repository at this point in the history
…b148

Signed-off-by: Peter Bain <[email protected]>
  • Loading branch information
pdbain-ibm committed Dec 3, 2018
1 parent c050f7c commit 4e12a21
Showing 1 changed file with 30 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -746,6 +746,8 @@ private static String getModuleName(Module module) {
* @param targetClass Class which the referring class is accessing
* @throws IllegalAccessException if the targetClass is not visible
*/

/*[IF Sidecar19-SE-OpenJ9]*/
static void checkClassModuleVisibility(int accessMode, Module accessModule, Class<?> targetClass) throws IllegalAccessException {
if (INTERNAL_PRIVILEGED != accessMode) {
Module targetModule = targetClass.getModule();
Expand Down Expand Up @@ -777,7 +779,34 @@ private static IllegalAccessException throwIllegalAccessException(Module accessM
/*[MSG "K0679", "Module '{0}' no access to: package '{1}' because module '{0}' can't read module '{2}'"]*/
throw new IllegalAccessException(Msg.getString(msgId, getModuleName(accessModule), targetClassPackageName, getModuleName(targetModule)));
}

/*[ELSE]
static void checkClassModuleVisibility(int accessMode, Module accessModule, Class<?> targetClass) throws IllegalAccessException {
if (INTERNAL_PRIVILEGED != accessMode) {
Module targetModule = targetClass.getModule();
String targetClassPackageName = targetClass.getPackageName();
if ((UNCONDITIONAL & accessMode) == UNCONDITIONAL) {
/* publicLookup objects can see all unconditionally exported packages. */
if (!targetModule.isExported(targetClassPackageName)) {
/*[MSG "K0676", "Module '{0}' no access to: package '{1}' which is not exported by module '{2}'"]*/
throw new IllegalAccessException(Msg.getString("K0587", getModuleName(accessModule), targetClassPackageName, getModuleName(targetModule))); //$NON-NLS-1$
}
} else if (!(
Objects.equals(accessModule, targetModule)
|| (targetModule.isExported(targetClassPackageName, accessModule) && accessModule.canRead(targetModule)))
) {
if (!targetModule.isExported(targetClassPackageName, accessModule)) {
/*[MSG "K0677", "Module '{0}' no access to: package '{1}' which is not exported by module '{2}' to module '{0}'"]*/
throw new IllegalAccessException(Msg.getString("K0677", getModuleName(accessModule), targetClassPackageName, getModuleName(targetModule))); //$NON-NLS-1$
}
// here accessModule.canRead(targetModule) must be false
/*[MSG "K0679", "Module '{0}' no access to: package '{1}' because module '{0}' can't read module '{2}'"]*/
throw new IllegalAccessException(Msg.getString("K0679", getModuleName(accessModule), targetClassPackageName, getModuleName(targetModule))); //$NON-NLS-1$
}
}
}

/*[ENDIF]*/ /* Sidecar19-SE-OpenJ9 */
/*[ENDIF]*/

/*[IF Panama]*/
Expand Down

0 comments on commit 4e12a21

Please sign in to comment.