< prev index next >

src/hotspot/share/runtime/reflection.cpp

Print this page




 686   if (host_class == field_class) {
 687     return true;
 688   }
 689 
 690   if (access.is_protected()) {
 691     if (!protected_restriction) {
 692       // See if current_class (or outermost host class) is a subclass of field_class
 693       // An interface may not access protected members of j.l.Object
 694       if (!host_class->is_interface() && host_class->is_subclass_of(field_class)) {
 695         if (access.is_static() || // static fields are ok, see 6622385
 696             current_class == resolved_class ||
 697             field_class == resolved_class ||
 698             host_class->is_subclass_of(resolved_class) ||
 699             resolved_class->is_subclass_of(host_class)) {
 700           return true;
 701         }
 702       }
 703     }
 704   }
 705 

 706   if (!access.is_private() && is_same_class_package(current_class, field_class)) {
 707     return true;
 708   }
 709 




















 710   // Allow all accesses from jdk/internal/reflect/MagicAccessorImpl subclasses to
 711   // succeed trivially.
 712   if (current_class->is_subclass_of(SystemDictionary::reflect_MagicAccessorImpl_klass())) {
 713     return true;
 714   }
 715 
 716   return can_relax_access_check_for(
 717     current_class, field_class, classloader_only);
 718 }
 719 
 720 bool Reflection::is_same_class_package(const Klass* class1, const Klass* class2) {
 721   return InstanceKlass::cast(class1)->is_same_class_package(class2);
 722 }
 723 
 724 // Checks that the 'outer' klass has declared 'inner' as being an inner klass. If not,
 725 // throw an incompatible class change exception
 726 // If inner_is_member, require the inner to be a member of the outer.
 727 // If !inner_is_member, require the inner to be anonymous (a non-member).
 728 // Caller is responsible for figuring out in advance which case must be true.
 729 void Reflection::check_for_inner_class(const InstanceKlass* outer, const InstanceKlass* inner,
 730                                        bool inner_is_member, TRAPS) {
 731   InnerClassesIterator iter(outer);
 732   constantPoolHandle cp   (THREAD, outer->constants());
 733   for (; !iter.done(); iter.next()) {
 734      int ioff = iter.inner_class_info_index();
 735      int ooff = iter.outer_class_info_index();
 736 
 737      if (inner_is_member && ioff != 0 && ooff != 0) {




 686   if (host_class == field_class) {
 687     return true;
 688   }
 689 
 690   if (access.is_protected()) {
 691     if (!protected_restriction) {
 692       // See if current_class (or outermost host class) is a subclass of field_class
 693       // An interface may not access protected members of j.l.Object
 694       if (!host_class->is_interface() && host_class->is_subclass_of(field_class)) {
 695         if (access.is_static() || // static fields are ok, see 6622385
 696             current_class == resolved_class ||
 697             field_class == resolved_class ||
 698             host_class->is_subclass_of(resolved_class) ||
 699             resolved_class->is_subclass_of(host_class)) {
 700           return true;
 701         }
 702       }
 703     }
 704   }
 705 
 706   // package access
 707   if (!access.is_private() && is_same_class_package(current_class, field_class)) {
 708     return true;
 709   }
 710 
 711   // private access between different classes needs a nestmate check, but
 712   // not for anonymous classes - so check host_class
 713   if (access.is_private() && host_class == current_class) {
 714     // FIXME: can we actually get here with non-instance classes?
 715     if (current_class->is_instance_klass() && field_class->is_instance_klass() ) {
 716       InstanceKlass* cur_ik = const_cast<InstanceKlass*>(InstanceKlass::cast(current_class));
 717       InstanceKlass* field_ik = const_cast<InstanceKlass*>(InstanceKlass::cast(field_class));
 718       // Nestmate access checks may require resolution and validation of the nest-host
 719       Thread* THREAD = Thread::current();
 720       bool access = cur_ik->has_nestmate_access_to(field_ik, THREAD);
 721       if (HAS_PENDING_EXCEPTION) {
 722         return false;
 723       }
 724       if (access) {
 725         guarantee(resolved_class->is_subclass_of(field_class), "must be!");
 726         return true;
 727       }
 728     }
 729   }
 730 
 731   // Allow all accesses from jdk/internal/reflect/MagicAccessorImpl subclasses to
 732   // succeed trivially.
 733   if (current_class->is_subclass_of(SystemDictionary::reflect_MagicAccessorImpl_klass())) {
 734     return true;
 735   }
 736 
 737   // Check for special relaxations
 738   return can_relax_access_check_for(current_class, field_class, classloader_only);
 739 }
 740 
 741 bool Reflection::is_same_class_package(const Klass* class1, const Klass* class2) {
 742   return InstanceKlass::cast(class1)->is_same_class_package(class2);
 743 }
 744 
 745 // Checks that the 'outer' klass has declared 'inner' as being an inner klass. If not,
 746 // throw an incompatible class change exception
 747 // If inner_is_member, require the inner to be a member of the outer.
 748 // If !inner_is_member, require the inner to be anonymous (a non-member).
 749 // Caller is responsible for figuring out in advance which case must be true.
 750 void Reflection::check_for_inner_class(const InstanceKlass* outer, const InstanceKlass* inner,
 751                                        bool inner_is_member, TRAPS) {
 752   InnerClassesIterator iter(outer);
 753   constantPoolHandle cp   (THREAD, outer->constants());
 754   for (; !iter.done(); iter.next()) {
 755      int ioff = iter.inner_class_info_index();
 756      int ooff = iter.outer_class_info_index();
 757 
 758      if (inner_is_member && ioff != 0 && ooff != 0) {


< prev index next >