changeset 14660:7d1db02e8d8f

AccessControlTest.java failing since merge with JEP 274
author alanb
date Sat, 05 Dec 2015 16:07:01 +0000
parents e9c02ef97b43
children e4af8eb551c3
files test/java/lang/invoke/AccessControlTest.java
diffstat 1 files changed, 22 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/test/java/lang/invoke/AccessControlTest.java	Fri Dec 04 08:12:13 2015 +0000
+++ b/test/java/lang/invoke/AccessControlTest.java	Sat Dec 05 16:07:01 2015 +0000
@@ -230,8 +230,10 @@
             Class<?> c1 = lookupClass();
             Class<?> c2 = m.getDeclaringClass();
 
-            // if public access then public members in an unnamed module can be accessed
-            if ((lookupModes & PUBLIC) != 0
+            // if the lookup class is in a loose module with PUBLIC access then
+            // public members of public types in all unnamed modules can be accessed
+            if (c1.getModule().canRead(null)
+                && (lookupModes & PUBLIC) != 0
                 && (!c2.getModule().isNamed())
                 && Modifier.isPublic(c2.getModifiers())
                 && Modifier.isPublic(m.getModifiers()))
@@ -258,9 +260,25 @@
         /** Predict the success or failure of accessing this class. */
         public boolean willAccessClass(Class<?> c2, boolean load) {
             Class<?> c1 = lookupClass();
-            if (load && c1.getClassLoader() == null) {
-                return false;
+            if (load && c2.getClassLoader() != null) {
+                if (c1.getClassLoader() == null) {
+                    // not visible
+                    return false;
+                }
+                if (c1 == publicLookup().lookupClass()) {
+                    // not visible as lookup class is defined by child of the boot loader
+                    return false;
+                }
             }
+
+            // if the lookup class is in a loose module with PUBLIC access then
+            // public types in all unnamed modules can be accessed
+            if (c1.getModule().canRead(null)
+                && (lookupModes & PUBLIC) != 0
+                && (!c2.getModule().isNamed())
+                && Modifier.isPublic(c2.getModifiers()))
+                return true;
+
             LookupCase lc = this.in(c2);
             int m1 = lc.lookupModes();
             boolean r = false;