< prev index next >

src/java.base/share/classes/jdk/internal/reflect/Reflection.java

Print this page
rev 50246 : imported patch jep181-rev1
rev 50247 : imported patch jep181-rev2
rev 50248 : [mq]: jep181-rev3

@@ -1,7 +1,7 @@
 /*
- * Copyright (c) 2001, 2017, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2001, 2018, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
  * under the terms of the GNU General Public License version 2 only, as
  * published by the Free Software Foundation.  Oracle designates this

@@ -141,10 +141,19 @@
 
         if (Modifier.isPublic(modifiers)) {
             return true;
         }
 
+        // Check for nestmate access if member is private
+        if (Modifier.isPrivate(modifiers)) {
+            // Note: targetClass may be outside the nest, but that is okay
+            //       as long as memberClass is in the nest.
+            if (areNestMates(currentClass, memberClass)) {
+                return true;
+            }
+        }
+
         boolean successSoFar = false;
 
         if (Modifier.isProtected(modifiers)) {
             // See if currentClass is a subclass of memberClass
             if (isSubclassOf(currentClass, memberClass)) {

@@ -349,6 +358,14 @@
             if (m2.isNamed()) msg += " to " + m1;
         }
 
         return new IllegalAccessException(msg);
     }
+
+    /**
+     * Returns true if {@code currentClass} and {@code memberClass}
+     * are nestmates - that is, if they have the same nesthost as
+     * determined by the VM.
+     */
+    public static native boolean areNestMates(Class<?> currentClass,
+                                              Class<?> memberClass);
 }
< prev index next >