changeset 5796:9a60f4ac6a37

8027458: VM anonymous classes: wrong context for protected access checks Summary: Use the anonymous class's host class for protected access checks Reviewed-by: acorn, coleenp, lfoltan
author hseigel
date Wed, 04 Dec 2013 08:10:31 -0500
parents e84d2afb2fb0
children a4f036ef52e8
files src/share/vm/runtime/reflection.cpp
diffstat 1 files changed, 15 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/src/share/vm/runtime/reflection.cpp	Tue Dec 03 13:56:10 2013 -0800
+++ b/src/share/vm/runtime/reflection.cpp	Wed Dec 04 08:10:31 2013 -0500
@@ -537,15 +537,26 @@
     return true;
   }
 
+  Klass* host_class = current_class;
+  while (host_class->oop_is_instance() &&
+         InstanceKlass::cast(host_class)->is_anonymous()) {
+    Klass* next_host_class = InstanceKlass::cast(host_class)->host_klass();
+    if (next_host_class == NULL)  break;
+    host_class = next_host_class;
+  }
+  if (host_class == field_class) {
+    return true;
+  }
+
   if (access.is_protected()) {
     if (!protected_restriction) {
-      // See if current_class is a subclass of field_class
-      if (current_class->is_subclass_of(field_class)) {
+      // See if current_class (or outermost host class) is a subclass of field_class
+      if (host_class->is_subclass_of(field_class)) {
         if (access.is_static() || // static fields are ok, see 6622385
             current_class == resolved_class ||
             field_class == resolved_class ||
-            current_class->is_subclass_of(resolved_class) ||
-            resolved_class->is_subclass_of(current_class)) {
+            host_class->is_subclass_of(resolved_class) ||
+            resolved_class->is_subclass_of(host_class)) {
           return true;
         }
       }