< prev index next >
src/java.base/share/classes/jdk/internal/reflect/Reflection.java
Print this page
*** 1,7 ****
/*
! * Copyright (c) 2001, 2013, 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, 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
*** 209,227 ****
// module may be null during startup (initLevel 0)
if (currentModule == memberModule)
return true; // same module (named or unnamed)
! // memberClass may be primitive or array class
! Class<?> c = memberClass;
! while (c.isArray()) {
! c = c.getComponentType();
! }
! if (c.isPrimitive())
! return true;
!
! String pkg = c.getPackageName();
boolean allowed = memberModule.isExported(pkg, currentModule);
if (allowed && memberModule.isNamed() && printStackTraceWhenAccessSucceeds()) {
if (!SharedSecrets.getJavaLangReflectModuleAccess()
.isStaticallyExported(memberModule, pkg, currentModule)) {
String msg = currentModule + " allowed access to member of " + memberClass;
--- 209,219 ----
// module may be null during startup (initLevel 0)
if (currentModule == memberModule)
return true; // same module (named or unnamed)
! String pkg = memberClass.getPackageName();
boolean allowed = memberModule.isExported(pkg, currentModule);
if (allowed && memberModule.isNamed() && printStackTraceWhenAccessSucceeds()) {
if (!SharedSecrets.getJavaLangReflectModuleAccess()
.isStaticallyExported(memberModule, pkg, currentModule)) {
String msg = currentModule + " allowed access to member of " + memberClass;
*** 235,248 ****
* Returns true if two classes in the same package.
*/
private static boolean isSameClassPackage(Class<?> c1, Class<?> c2) {
if (c1.getClassLoader() != c2.getClassLoader())
return false;
- while (c1.isArray())
- c1 = c1.getComponentType();
- while (c2.isArray())
- c2 = c2.getComponentType();
return Objects.equals(c1.getPackageName(), c2.getPackageName());
}
static boolean isSubclassOf(Class<?> queryClass,
Class<?> ofClass)
--- 227,236 ----
*** 376,391 ****
}
printStackPropertiesSet = true;
}
}
- public static void enableStackTraces() {
- printStackWhenAccessFails = true;
- printStackWhenAccessSucceeds = true;
- printStackPropertiesSet = true;
- }
-
public static boolean printStackTraceWhenAccessFails() {
ensurePrintStackPropertiesSet();
return printStackWhenAccessFails;
}
--- 364,373 ----
*** 411,425 ****
currentSuffix = " (in " + m1 + ")";
Module m2 = memberClass.getModule();
if (m2.isNamed())
memberSuffix = " (in " + m2 + ")";
! Class<?> c = memberClass;
! while (c.isArray()) {
! c = c.getComponentType();
! }
! String memberPackageName = c.getPackageName();
String msg = currentClass + currentSuffix + " cannot access ";
if (m2.isExported(memberPackageName, m1)) {
// module access okay so include the modifiers in the message
--- 393,403 ----
currentSuffix = " (in " + m1 + ")";
Module m2 = memberClass.getModule();
if (m2.isNamed())
memberSuffix = " (in " + m2 + ")";
! String memberPackageName = memberClass.getPackageName();
String msg = currentClass + currentSuffix + " cannot access ";
if (m2.isExported(memberPackageName, m1)) {
// module access okay so include the modifiers in the message
< prev index next >