< prev index next >

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

Print this page
rev 56007 : 8229773: Resolve permissions for code source URLs lazily
Reviewed-by: alanb, mullan, rriggs, dfuchs


  57 import java.util.PropertyPermission;
  58 import java.util.ResourceBundle;
  59 import java.util.function.Supplier;
  60 import java.util.concurrent.ConcurrentHashMap;
  61 import java.util.stream.Stream;
  62 
  63 import jdk.internal.util.StaticProperty;
  64 import jdk.internal.module.ModuleBootstrap;
  65 import jdk.internal.module.ServicesCatalog;
  66 import jdk.internal.reflect.CallerSensitive;
  67 import jdk.internal.reflect.Reflection;
  68 import jdk.internal.HotSpotIntrinsicCandidate;
  69 import jdk.internal.access.JavaLangAccess;
  70 import jdk.internal.access.SharedSecrets;
  71 import jdk.internal.misc.VM;
  72 import jdk.internal.logger.LoggerFinderLoader;
  73 import jdk.internal.logger.LazyLoggers;
  74 import jdk.internal.logger.LocalizedLoggerWrapper;
  75 import jdk.internal.util.SystemProps;
  76 import jdk.internal.vm.annotation.Stable;

  77 import sun.reflect.annotation.AnnotationType;
  78 import sun.nio.ch.Interruptible;
  79 import sun.security.util.SecurityConstants;
  80 
  81 /**
  82  * The {@code System} class contains several useful class fields
  83  * and methods. It cannot be instantiated.
  84  *
  85  * Among the facilities provided by the {@code System} class
  86  * are standard input, standard output, and error output streams;
  87  * access to externally defined properties and environment
  88  * variables; a means of loading files and libraries; and a utility
  89  * method for quickly copying a portion of an array.
  90  *
  91  * @since   1.0
  92  */
  93 public final class System {
  94     /* Register the natives via the static initializer.
  95      *
  96      * VM will invoke the initializeSystemClass method to complete


 322      * started with the system property {@code java.security.manager} set to
 323      * the special token "{@code disallow}" then the {@code setSecurityManager}
 324      * method cannot be used to set a security manager.
 325      *
 326      * @param  sm the security manager or {@code null}
 327      * @throws SecurityException
 328      *         if the security manager has already been set and its {@code
 329      *         checkPermission} method doesn't allow it to be replaced
 330      * @throws UnsupportedOperationException
 331      *         if {@code sm} is non-null and a security manager is not allowed
 332      *         to be set dynamically
 333      * @see #getSecurityManager
 334      * @see SecurityManager#checkPermission
 335      * @see java.lang.RuntimePermission
 336      */
 337     public static void setSecurityManager(SecurityManager sm) {
 338         if (allowSecurityManager()) {
 339             if (security == null) {
 340                 // ensure image reader is initialized
 341                 Object.class.getResource("java/lang/ANY");


 342             }
 343             if (sm != null) {
 344                 try {
 345                     // pre-populates the SecurityManager.packageAccess cache
 346                     // to avoid recursive permission checking issues with custom
 347                     // SecurityManager implementations
 348                     sm.checkPackageAccess("java.lang");
 349                 } catch (Exception e) {
 350                     // no-op
 351                 }
 352             }
 353             setSecurityManager0(sm);
 354         } else {
 355             // security manager not allowed
 356             if (sm != null) {
 357                 throw new UnsupportedOperationException(
 358                     "Runtime configured to disallow security manager");
 359             }
 360         }
 361     }




  57 import java.util.PropertyPermission;
  58 import java.util.ResourceBundle;
  59 import java.util.function.Supplier;
  60 import java.util.concurrent.ConcurrentHashMap;
  61 import java.util.stream.Stream;
  62 
  63 import jdk.internal.util.StaticProperty;
  64 import jdk.internal.module.ModuleBootstrap;
  65 import jdk.internal.module.ServicesCatalog;
  66 import jdk.internal.reflect.CallerSensitive;
  67 import jdk.internal.reflect.Reflection;
  68 import jdk.internal.HotSpotIntrinsicCandidate;
  69 import jdk.internal.access.JavaLangAccess;
  70 import jdk.internal.access.SharedSecrets;
  71 import jdk.internal.misc.VM;
  72 import jdk.internal.logger.LoggerFinderLoader;
  73 import jdk.internal.logger.LazyLoggers;
  74 import jdk.internal.logger.LocalizedLoggerWrapper;
  75 import jdk.internal.util.SystemProps;
  76 import jdk.internal.vm.annotation.Stable;
  77 import sun.nio.fs.DefaultFileSystemProvider;
  78 import sun.reflect.annotation.AnnotationType;
  79 import sun.nio.ch.Interruptible;
  80 import sun.security.util.SecurityConstants;
  81 
  82 /**
  83  * The {@code System} class contains several useful class fields
  84  * and methods. It cannot be instantiated.
  85  *
  86  * Among the facilities provided by the {@code System} class
  87  * are standard input, standard output, and error output streams;
  88  * access to externally defined properties and environment
  89  * variables; a means of loading files and libraries; and a utility
  90  * method for quickly copying a portion of an array.
  91  *
  92  * @since   1.0
  93  */
  94 public final class System {
  95     /* Register the natives via the static initializer.
  96      *
  97      * VM will invoke the initializeSystemClass method to complete


 323      * started with the system property {@code java.security.manager} set to
 324      * the special token "{@code disallow}" then the {@code setSecurityManager}
 325      * method cannot be used to set a security manager.
 326      *
 327      * @param  sm the security manager or {@code null}
 328      * @throws SecurityException
 329      *         if the security manager has already been set and its {@code
 330      *         checkPermission} method doesn't allow it to be replaced
 331      * @throws UnsupportedOperationException
 332      *         if {@code sm} is non-null and a security manager is not allowed
 333      *         to be set dynamically
 334      * @see #getSecurityManager
 335      * @see SecurityManager#checkPermission
 336      * @see java.lang.RuntimePermission
 337      */
 338     public static void setSecurityManager(SecurityManager sm) {
 339         if (allowSecurityManager()) {
 340             if (security == null) {
 341                 // ensure image reader is initialized
 342                 Object.class.getResource("java/lang/ANY");
 343                 // ensure the default file system is initialized
 344                 DefaultFileSystemProvider.theFileSystem();
 345             }
 346             if (sm != null) {
 347                 try {
 348                     // pre-populates the SecurityManager.packageAccess cache
 349                     // to avoid recursive permission checking issues with custom
 350                     // SecurityManager implementations
 351                     sm.checkPackageAccess("java.lang");
 352                 } catch (Exception e) {
 353                     // no-op
 354                 }
 355             }
 356             setSecurityManager0(sm);
 357         } else {
 358             // security manager not allowed
 359             if (sm != null) {
 360                 throw new UnsupportedOperationException(
 361                     "Runtime configured to disallow security manager");
 362             }
 363         }
 364     }


< prev index next >