< prev index next >
src/java.base/share/classes/jdk/internal/reflect/Reflection.java
Print this page
*** 1,7 ****
/*
! * Copyright (c) 2001, 2017, 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
--- 1,7 ----
/*
! * 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,150 ****
--- 141,161 ----
if (Modifier.isPublic(modifiers)) {
return true;
}
+ // Check for nestmate access if member is private
+ if (Modifier.isPrivate(modifiers)) {
+ // assert: isSubclassof(targetClass, memberClass)
+ // Note: targetClass may be outside the nest, but that is okay
+ // as long as memberClass is in the nest.
+ boolean nestmates = areNestMates(currentClass, memberClass);
+ if (nestmates) {
+ return true;
+ }
+ }
+
boolean successSoFar = false;
if (Modifier.isProtected(modifiers)) {
// See if currentClass is a subclass of memberClass
if (isSubclassOf(currentClass, memberClass)) {
*** 349,354 ****
--- 360,373 ----
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 >