changeset 6696:a56eb4f80123 jdk7u45-b03

8014349: (cl) Class.getDeclaredClass problematic in some class loader configurations Reviewed-by: mchung, ahgross, darcy
author jfranck
date Mon, 15 Jul 2013 18:41:54 +0200
parents 328d974d2eb8
children 0b2f8e7cfadd
files src/share/classes/java/lang/Class.java src/share/classes/java/lang/invoke/MethodHandleNatives.java src/share/native/java/lang/Class.c
diffstat 3 files changed, 13 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/src/share/classes/java/lang/Class.java	Mon Jul 15 16:00:57 2013 +0100
+++ b/src/share/classes/java/lang/Class.java	Mon Jul 15 18:41:54 2013 +0200
@@ -1096,7 +1096,17 @@
      * @return the declaring class for this class
      * @since JDK1.1
      */
-    public native Class<?> getDeclaringClass();
+    @CallerSensitive
+    public Class<?> getDeclaringClass() {
+        final Class<?> candidate = getDeclaringClass0();
+
+        if (candidate != null)
+            candidate.checkPackageAccess(
+                    ClassLoader.getClassLoader(Reflection.getCallerClass()), true);
+        return candidate;
+    }
+
+    private native Class<?> getDeclaringClass0();
 
 
     /**
--- a/src/share/classes/java/lang/invoke/MethodHandleNatives.java	Mon Jul 15 16:00:57 2013 +0100
+++ b/src/share/classes/java/lang/invoke/MethodHandleNatives.java	Mon Jul 15 18:41:54 2013 +0200
@@ -456,6 +456,7 @@
         case "getDeclaredField":
         case "getDeclaredMethod":
         case "getDeclaredConstructor":
+        case "getDeclaringClass":
         case "getEnclosingClass":
         case "getEnclosingMethod":
         case "getEnclosingConstructor":
--- a/src/share/native/java/lang/Class.c	Mon Jul 15 16:00:57 2013 +0100
+++ b/src/share/native/java/lang/Class.c	Mon Jul 15 18:41:54 2013 +0200
@@ -70,7 +70,7 @@
     {"getProtectionDomain0", "()" PD,       (void *)&JVM_GetProtectionDomain},
     {"setProtectionDomain0", "(" PD ")V",   (void *)&JVM_SetProtectionDomain},
     {"getDeclaredClasses0",  "()[" CLS,      (void *)&JVM_GetDeclaredClasses},
-    {"getDeclaringClass",   "()" CLS,      (void *)&JVM_GetDeclaringClass},
+    {"getDeclaringClass0",   "()" CLS,      (void *)&JVM_GetDeclaringClass},
     {"getGenericSignature", "()" STR,       (void *)&JVM_GetClassSignature},
     {"getRawAnnotations",      "()" BA,        (void *)&JVM_GetClassAnnotations},
     {"getConstantPool",     "()" CPL,       (void *)&JVM_GetClassConstantPool},