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 public void checkMemberAccess(Class<?> clazz, int which) { 1683 if (clazz == null) { 1684 throw new NullPointerException("class can't be null"); 1685 } 1686 if (which != Member.PUBLIC) { 1687 Class stack[] = getClassContext(); 1688 /* 1689 * stack depth of 4 should be the caller of one of the 1690 * methods in java.lang.Class that invoke checkMember 1691 * access. The stack should look like: 1692 * 1693 * someCaller [3] 1694 * java.lang.Class.someReflectionAPI [2] 1695 * java.lang.Class.checkMemberAccess [1] 1696 * SecurityManager.checkMemberAccess [0] 1697 * 1698 */ 1699 if ((stack.length<4) || 1700 (stack[3].getClassLoader() != clazz.getClassLoader())) { 1701 checkPermission(SecurityConstants.CHECK_MEMBER_ACCESS_PERMISSION); | 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 * This method will be modified to throw {@code SecurityException} 1682 * in a future release. Use the {@link #checkPermission} 1683 * method instead to perform the appropriate permission check. 1684 * 1685 * @see java.lang.reflect.Member 1686 * @since JDK1.1 1687 * @see #checkPermission(java.security.Permission) checkPermission 1688 */ 1689 @Deprecated 1690 public void checkMemberAccess(Class<?> clazz, int which) { 1691 if (clazz == null) { 1692 throw new NullPointerException("class can't be null"); 1693 } 1694 if (which != Member.PUBLIC) { 1695 Class stack[] = getClassContext(); 1696 /* 1697 * stack depth of 4 should be the caller of one of the 1698 * methods in java.lang.Class that invoke checkMember 1699 * access. The stack should look like: 1700 * 1701 * someCaller [3] 1702 * java.lang.Class.someReflectionAPI [2] 1703 * java.lang.Class.checkMemberAccess [1] 1704 * SecurityManager.checkMemberAccess [0] 1705 * 1706 */ 1707 if ((stack.length<4) || 1708 (stack[3].getClassLoader() != clazz.getClassLoader())) { 1709 checkPermission(SecurityConstants.CHECK_MEMBER_ACCESS_PERMISSION); |