jdk/src/share/classes/java/lang/Class.java
changeset 18263 69df685432b7
parent 18253 4323a5fe8bc4
child 18276 63b45dc8848c
equal deleted inserted replaced
18262:ee7c925ab7ed 18263:69df685432b7
   968      *
   968      *
   969      *             <ul>
   969      *             <ul>
   970      *
   970      *
   971      *             <li> invocation of
   971      *             <li> invocation of
   972      *             {@link SecurityManager#checkMemberAccess
   972      *             {@link SecurityManager#checkMemberAccess
   973      *             s.checkMemberAccess(enclosingClass, Member.PUBLIC)} denies
   973      *             s.checkMemberAccess(enclosingClass, Member.DECLARED)} denies
   974      *             access to the methods within the enclosing class
   974      *             access to the methods within the enclosing class
   975      *
   975      *
   976      *             <li> the caller's class loader is not the same as or an
   976      *             <li> the caller's class loader is not the same as or an
   977      *             ancestor of the class loader for the enclosing class and
   977      *             ancestor of the class loader for the enclosing class and
   978      *             invocation of {@link SecurityManager#checkPackageAccess
   978      *             invocation of {@link SecurityManager#checkPackageAccess
  1124      *
  1124      *
  1125      *             <ul>
  1125      *             <ul>
  1126      *
  1126      *
  1127      *             <li> invocation of
  1127      *             <li> invocation of
  1128      *             {@link SecurityManager#checkMemberAccess
  1128      *             {@link SecurityManager#checkMemberAccess
  1129      *             s.checkMemberAccess(enclosingClass, Member.PUBLIC)} denies
  1129      *             s.checkMemberAccess(enclosingClass, Member.DECLARED)} denies
  1130      *             access to the constructors within the enclosing class
  1130      *             access to the constructors within the enclosing class
  1131      *
  1131      *
  1132      *             <li> the caller's class loader is not the same as or an
  1132      *             <li> the caller's class loader is not the same as or an
  1133      *             ancestor of the class loader for the enclosing class and
  1133      *             ancestor of the class loader for the enclosing class and
  1134      *             invocation of {@link SecurityManager#checkPackageAccess
  1134      *             invocation of {@link SecurityManager#checkPackageAccess
  1246                 throw new InternalError("Malformed enclosing method information");
  1246                 throw new InternalError("Malformed enclosing method information");
  1247             else
  1247             else
  1248                 enclosingCandidate = enclosingClass;
  1248                 enclosingCandidate = enclosingClass;
  1249         }
  1249         }
  1250 
  1250 
  1251         // be very careful not to change the stack depth of this
  1251         if (enclosingCandidate != null)
  1252         // checkMemberAccess call for security reasons
  1252             enclosingCandidate.checkPackageAccess(
  1253         // see java.lang.SecurityManager.checkMemberAccess
  1253                     ClassLoader.getClassLoader(Reflection.getCallerClass()), true);
  1254         if (enclosingCandidate != null) {
       
  1255             enclosingCandidate.checkMemberAccess(Member.DECLARED,
       
  1256                                                  Reflection.getCallerClass(), true);
       
  1257         }
       
  1258         return enclosingCandidate;
  1254         return enclosingCandidate;
  1259     }
  1255     }
  1260 
  1256 
  1261     /**
  1257     /**
  1262      * Returns the simple name of the underlying class as given in the
  1258      * Returns the simple name of the underlying class as given in the
  2301 
  2297 
  2302     /*
  2298     /*
  2303      * Check if client is allowed to access members.  If access is denied,
  2299      * Check if client is allowed to access members.  If access is denied,
  2304      * throw a SecurityException.
  2300      * throw a SecurityException.
  2305      *
  2301      *
       
  2302      * This method also enforces package access.
       
  2303      *
  2306      * <p> Default policy: allow all clients access with normal Java access
  2304      * <p> Default policy: allow all clients access with normal Java access
  2307      * control.
  2305      * control.
  2308      */
  2306      */
  2309     private void checkMemberAccess(int which, Class<?> caller, boolean checkProxyInterfaces) {
  2307     private void checkMemberAccess(int which, Class<?> caller, boolean checkProxyInterfaces) {
  2310         final SecurityManager s = System.getSecurityManager();
  2308         final SecurityManager s = System.getSecurityManager();
  2321             } else {
  2319             } else {
  2322                 // Don't refactor; otherwise break the stack depth for
  2320                 // Don't refactor; otherwise break the stack depth for
  2323                 // checkMemberAccess of subclasses of SecurityManager as specified.
  2321                 // checkMemberAccess of subclasses of SecurityManager as specified.
  2324                 s.checkMemberAccess(this, which);
  2322                 s.checkMemberAccess(this, which);
  2325             }
  2323             }
  2326 
  2324             this.checkPackageAccess(ccl, checkProxyInterfaces);
       
  2325         }
       
  2326     }
       
  2327 
       
  2328     /*
       
  2329      * Checks if a client loaded in ClassLoader ccl is allowed to access this
       
  2330      * class under the current package access policy. If access is denied,
       
  2331      * throw a SecurityException.
       
  2332      */
       
  2333     private void checkPackageAccess(final ClassLoader ccl, boolean checkProxyInterfaces) {
       
  2334         final SecurityManager s = System.getSecurityManager();
       
  2335         if (s != null) {
       
  2336             final ClassLoader cl = getClassLoader0();
  2327 
  2337 
  2328             if (ReflectUtil.needsPackageAccessCheck(ccl, cl)) {
  2338             if (ReflectUtil.needsPackageAccessCheck(ccl, cl)) {
  2329                 String name = this.getName();
  2339                 String name = this.getName();
  2330                 int i = name.lastIndexOf('.');
  2340                 int i = name.lastIndexOf('.');
  2331                 if (i != -1) {
  2341                 if (i != -1) {