1658 * The default policy is to allow access to PUBLIC members, as well 1659 * as access to classes that have the same class loader as the caller. 1660 * In all other cases, this method calls <code>checkPermission</code> 1661 * with the <code>RuntimePermission("accessDeclaredMembers") 1662 * </code> permission. 1663 * <p> 1664 * If this method is overridden, then a call to 1665 * <code>super.checkMemberAccess</code> cannot be made, 1666 * as the default implementation of <code>checkMemberAccess</code> 1667 * relies on the code being checked being at a stack depth of 1668 * 4. 1669 * 1670 * @param clazz the class that reflection is to be performed on. 1671 * 1672 * @param which type of access, PUBLIC or DECLARED. 1673 * 1674 * @exception SecurityException if the caller does not have 1675 * permission to access members. 1676 * @exception NullPointerException if the <code>clazz</code> argument is 1677 * <code>null</code>. 1678 * @see java.lang.reflect.Member 1679 * @since JDK1.1 1680 * @see #checkPermission(java.security.Permission) checkPermission 1681 */ 1682 @CallerSensitive 1683 public void checkMemberAccess(Class<?> clazz, int which) { 1684 if (clazz == null) { 1685 throw new NullPointerException("class can't be null"); 1686 } 1687 if (which != Member.PUBLIC) { 1688 Class stack[] = getClassContext(); 1689 /* 1690 * stack depth of 4 should be the caller of one of the 1691 * methods in java.lang.Class that invoke checkMember 1692 * access. The stack should look like: 1693 * 1694 * someCaller [3] 1695 * java.lang.Class.someReflectionAPI [2] 1696 * java.lang.Class.checkMemberAccess [1] 1697 * SecurityManager.checkMemberAccess [0] 1698 * 1699 */ 1700 if ((stack.length<4) || 1701 (stack[3].getClassLoader() != clazz.getClassLoader())) { | 1658 * The default policy is to allow access to PUBLIC members, as well 1659 * as access to classes that have the same class loader as the caller. 1660 * In all other cases, this method calls <code>checkPermission</code> 1661 * with the <code>RuntimePermission("accessDeclaredMembers") 1662 * </code> permission. 1663 * <p> 1664 * If this method is overridden, then a call to 1665 * <code>super.checkMemberAccess</code> cannot be made, 1666 * as the default implementation of <code>checkMemberAccess</code> 1667 * relies on the code being checked being at a stack depth of 1668 * 4. 1669 * 1670 * @param clazz the class that reflection is to be performed on. 1671 * 1672 * @param which type of access, PUBLIC or DECLARED. 1673 * 1674 * @exception SecurityException if the caller does not have 1675 * permission to access members. 1676 * @exception NullPointerException if the <code>clazz</code> argument is 1677 * <code>null</code>. 1678 * 1679 * @deprecated This method relies on the caller being at a stack depth 1680 * of 4 which is error-prone and cannot be enforced by the runtime. 1681 * Users of this method should instead invoke {@link #checkPermission} 1682 * directly. This method will be changed in a future release 1683 * to check the permission {@code java.security.AllPermission}. 1684 * 1685 * @see java.lang.reflect.Member 1686 * @since JDK1.1 1687 * @see #checkPermission(java.security.Permission) checkPermission 1688 */ 1689 @Deprecated 1690 @CallerSensitive 1691 public void checkMemberAccess(Class<?> clazz, int which) { 1692 if (clazz == null) { 1693 throw new NullPointerException("class can't be null"); 1694 } 1695 if (which != Member.PUBLIC) { 1696 Class stack[] = getClassContext(); 1697 /* 1698 * stack depth of 4 should be the caller of one of the 1699 * methods in java.lang.Class that invoke checkMember 1700 * access. The stack should look like: 1701 * 1702 * someCaller [3] 1703 * java.lang.Class.someReflectionAPI [2] 1704 * java.lang.Class.checkMemberAccess [1] 1705 * SecurityManager.checkMemberAccess [0] 1706 * 1707 */ 1708 if ((stack.length<4) || 1709 (stack[3].getClassLoader() != clazz.getClassLoader())) { |