643 bool protected_restriction) { 644 // Verify that current_class can access a field of field_class, where that 645 // field's access bits are "access". We assume that we've already verified 646 // that current_class can access field_class. 647 // 648 // If the classloader_only flag is set, we automatically allow any accesses 649 // in which current_class doesn't have a classloader. 650 // 651 // "resolved_class" is the runtime type of "field_class". Sometimes we don't 652 // need this distinction (e.g. if all we have is the runtime type, or during 653 // class file parsing when we only care about the static type); in that case 654 // callers should ensure that resolved_class == field_class. 655 // 656 if ((current_class == NULL) || 657 (current_class == field_class) || 658 access.is_public()) { 659 return true; 660 } 661 662 const Klass* host_class = current_class; 663 while (host_class->is_instance_klass() && 664 InstanceKlass::cast(host_class)->is_anonymous()) { 665 const Klass* next_host_class = InstanceKlass::cast(host_class)->host_klass(); 666 if (next_host_class == NULL) break; 667 host_class = next_host_class; 668 } 669 if (host_class == field_class) { 670 return true; 671 } 672 673 if (access.is_protected()) { 674 if (!protected_restriction) { 675 // See if current_class (or outermost host class) is a subclass of field_class 676 // An interface may not access protected members of j.l.Object 677 if (!host_class->is_interface() && host_class->is_subclass_of(field_class)) { 678 if (access.is_static() || // static fields are ok, see 6622385 679 current_class == resolved_class || 680 field_class == resolved_class || 681 host_class->is_subclass_of(resolved_class) || 682 resolved_class->is_subclass_of(host_class)) { 683 return true; 684 } 685 } 686 } 687 } | 643 bool protected_restriction) { 644 // Verify that current_class can access a field of field_class, where that 645 // field's access bits are "access". We assume that we've already verified 646 // that current_class can access field_class. 647 // 648 // If the classloader_only flag is set, we automatically allow any accesses 649 // in which current_class doesn't have a classloader. 650 // 651 // "resolved_class" is the runtime type of "field_class". Sometimes we don't 652 // need this distinction (e.g. if all we have is the runtime type, or during 653 // class file parsing when we only care about the static type); in that case 654 // callers should ensure that resolved_class == field_class. 655 // 656 if ((current_class == NULL) || 657 (current_class == field_class) || 658 access.is_public()) { 659 return true; 660 } 661 662 const Klass* host_class = current_class; 663 if (host_class->is_instance_klass() && 664 InstanceKlass::cast(host_class)->is_anonymous()) { 665 host_class = InstanceKlass::cast(host_class)->host_klass(); 666 assert(host_class != NULL, "Anonymous class has null host class"); 667 assert(!host_class->is_instance_klass() || 668 !InstanceKlass::cast(host_class)->is_anonymous(), 669 "host_class should not be anonymous"); 670 } 671 if (host_class == field_class) { 672 return true; 673 } 674 675 if (access.is_protected()) { 676 if (!protected_restriction) { 677 // See if current_class (or outermost host class) is a subclass of field_class 678 // An interface may not access protected members of j.l.Object 679 if (!host_class->is_interface() && host_class->is_subclass_of(field_class)) { 680 if (access.is_static() || // static fields are ok, see 6622385 681 current_class == resolved_class || 682 field_class == resolved_class || 683 host_class->is_subclass_of(resolved_class) || 684 resolved_class->is_subclass_of(host_class)) { 685 return true; 686 } 687 } 688 } 689 } |