< prev index next >

src/java.base/share/classes/java/lang/Class.java

Print this page
rev 16881 : 8177036: Class.checkMemberAccess throws NPE when calling Class methods via JNI
Reviewed-by: mchung


2754     static native Class<?> getPrimitiveClass(String name);
2755 
2756     /*
2757      * Check if client is allowed to access members.  If access is denied,
2758      * throw a SecurityException.
2759      *
2760      * This method also enforces package access.
2761      *
2762      * <p> Default policy: allow all clients access with normal Java access
2763      * control.
2764      *
2765      * <p> NOTE: should only be called if a SecurityManager is installed
2766      */
2767     private void checkMemberAccess(SecurityManager sm, int which,
2768                                    Class<?> caller, boolean checkProxyInterfaces) {
2769         /* Default policy allows access to all {@link Member#PUBLIC} members,
2770          * as well as access to classes that have the same class loader as the caller.
2771          * In all other cases, it requires RuntimePermission("accessDeclaredMembers")
2772          * permission.
2773          */
2774         final ClassLoader ccl = caller.getClassLoader0();
2775         if (which != Member.PUBLIC) {
2776             final ClassLoader cl = getClassLoader0();
2777             if (ccl != cl) {
2778                 sm.checkPermission(SecurityConstants.CHECK_MEMBER_ACCESS_PERMISSION);
2779             }
2780         }
2781         this.checkPackageAccess(sm, ccl, checkProxyInterfaces);
2782     }
2783 
2784     /*
2785      * Checks if a client loaded in ClassLoader ccl is allowed to access this
2786      * class under the current package access policy. If access is denied,
2787      * throw a SecurityException.
2788      *
2789      * NOTE: this method should only be called if a SecurityManager is active
2790      */
2791     private void checkPackageAccess(SecurityManager sm, final ClassLoader ccl,
2792                                     boolean checkProxyInterfaces) {
2793         final ClassLoader cl = getClassLoader0();
2794 




2754     static native Class<?> getPrimitiveClass(String name);
2755 
2756     /*
2757      * Check if client is allowed to access members.  If access is denied,
2758      * throw a SecurityException.
2759      *
2760      * This method also enforces package access.
2761      *
2762      * <p> Default policy: allow all clients access with normal Java access
2763      * control.
2764      *
2765      * <p> NOTE: should only be called if a SecurityManager is installed
2766      */
2767     private void checkMemberAccess(SecurityManager sm, int which,
2768                                    Class<?> caller, boolean checkProxyInterfaces) {
2769         /* Default policy allows access to all {@link Member#PUBLIC} members,
2770          * as well as access to classes that have the same class loader as the caller.
2771          * In all other cases, it requires RuntimePermission("accessDeclaredMembers")
2772          * permission.
2773          */
2774         final ClassLoader ccl = ClassLoader.getClassLoader(caller);
2775         if (which != Member.PUBLIC) {
2776             final ClassLoader cl = getClassLoader0();
2777             if (ccl != cl) {
2778                 sm.checkPermission(SecurityConstants.CHECK_MEMBER_ACCESS_PERMISSION);
2779             }
2780         }
2781         this.checkPackageAccess(sm, ccl, checkProxyInterfaces);
2782     }
2783 
2784     /*
2785      * Checks if a client loaded in ClassLoader ccl is allowed to access this
2786      * class under the current package access policy. If access is denied,
2787      * throw a SecurityException.
2788      *
2789      * NOTE: this method should only be called if a SecurityManager is active
2790      */
2791     private void checkPackageAccess(SecurityManager sm, final ClassLoader ccl,
2792                                     boolean checkProxyInterfaces) {
2793         final ClassLoader cl = getClassLoader0();
2794 


< prev index next >