提交 2ed6a3a4 编写于 作者: J jfranck

8014349: (cl) Class.getDeclaredClass problematic in some class loader configurations

Reviewed-by: mchung, ahgross, darcy
上级 2abce32b
...@@ -1221,9 +1221,25 @@ public final class Class<T> implements java.io.Serializable, ...@@ -1221,9 +1221,25 @@ public final class Class<T> implements java.io.Serializable,
* type, or void,then this method returns null. * type, or void,then this method returns null.
* *
* @return the declaring class for this class * @return the declaring class for this class
* @throws SecurityException
* If a security manager, <i>s</i>, is present and the caller's
* class loader is not the same as or an ancestor of the class
* loader for the declaring class and invocation of {@link
* SecurityManager#checkPackageAccess s.checkPackageAccess()}
* denies access to the package of the declaring class
* @since JDK1.1 * @since JDK1.1
*/ */
public native Class<?> getDeclaringClass(); @CallerSensitive
public Class<?> getDeclaringClass() throws SecurityException {
final Class<?> candidate = getDeclaringClass0();
if (candidate != null)
candidate.checkPackageAccess(
ClassLoader.getClassLoader(Reflection.getCallerClass()), true);
return candidate;
}
private native Class<?> getDeclaringClass0();
/** /**
......
...@@ -69,7 +69,7 @@ static JNINativeMethod methods[] = { ...@@ -69,7 +69,7 @@ static JNINativeMethod methods[] = {
{"getDeclaredConstructors0","(Z)[" CTR, (void *)&JVM_GetClassDeclaredConstructors}, {"getDeclaredConstructors0","(Z)[" CTR, (void *)&JVM_GetClassDeclaredConstructors},
{"getProtectionDomain0", "()" PD, (void *)&JVM_GetProtectionDomain}, {"getProtectionDomain0", "()" PD, (void *)&JVM_GetProtectionDomain},
{"getDeclaredClasses0", "()[" CLS, (void *)&JVM_GetDeclaredClasses}, {"getDeclaredClasses0", "()[" CLS, (void *)&JVM_GetDeclaredClasses},
{"getDeclaringClass", "()" CLS, (void *)&JVM_GetDeclaringClass}, {"getDeclaringClass0", "()" CLS, (void *)&JVM_GetDeclaringClass},
{"getGenericSignature0", "()" STR, (void *)&JVM_GetClassSignature}, {"getGenericSignature0", "()" STR, (void *)&JVM_GetClassSignature},
{"getRawAnnotations", "()" BA, (void *)&JVM_GetClassAnnotations}, {"getRawAnnotations", "()" BA, (void *)&JVM_GetClassAnnotations},
{"getConstantPool", "()" CPL, (void *)&JVM_GetClassConstantPool}, {"getConstantPool", "()" CPL, (void *)&JVM_GetClassConstantPool},
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册