src/java.base/share/classes/jdk/internal/reflect/Reflection.java
changeset 50735 2f2af62dfac7
parent 48477 b7af6f568d00
child 51798 f55a4bc91ef4
--- a/src/java.base/share/classes/jdk/internal/reflect/Reflection.java	Fri Jun 22 17:49:21 2018 -0700
+++ b/src/java.base/share/classes/jdk/internal/reflect/Reflection.java	Sat Jun 23 01:32:41 2018 -0400
@@ -1,5 +1,5 @@
 /*
- * 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
@@ -143,6 +143,15 @@
             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)) {
@@ -351,4 +360,12 @@
 
         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);
 }