[Patch] java.lang - securitymanager handling

Michael Koch konqueror@gmx.de
Mon Apr 25 20:38:00 GMT 2005


Hi list,


I just commited the attached patch to replace
java.lang.Runtime.securityManager be java.lang.SecurityManager.current.
This is mainly to merge code with GNU classpath.


Michael


2005-04-25  Michael Koch  <konqueror@gmx.de>

	* java/lang/Runtime.java,
	java/lang/SecurityManager.java,
	java/lang/System.java,
	java/lang/ThreadGroup.java:
	Replaced java.lang.Runtime.securityManager by
	java.lang.SecurityManager.current (as used in GNU classpath).

-------------- next part --------------
Index: java/lang/Runtime.java
===================================================================
RCS file: /cvs/gcc/gcc/libjava/java/lang/Runtime.java,v
retrieving revision 1.20
diff -u -r1.20 Runtime.java
--- java/lang/Runtime.java	25 Apr 2005 19:48:35 -0000	1.20
+++ java/lang/Runtime.java	25 Apr 2005 20:34:51 -0000
@@ -65,14 +65,6 @@
    */
   private final String[] libpath;
 
-  /**
-   * The current security manager. This is located here instead of in
-   * System, to avoid security problems, as well as bootstrap issues.
-   * Make sure to access it in a thread-safe manner; it is package visible
-   * to avoid overhead in java.lang.
-   */
-  static SecurityManager securityManager;
-
   static
   {
     init();
@@ -151,7 +143,7 @@
    */
   public void exit(int status)
   {
-    SecurityManager sm = securityManager; // Be thread-safe!
+    SecurityManager sm = SecurityManager.current; // Be thread-safe!
     if (sm != null)
       sm.checkExit(status);
     boolean first = false;
@@ -279,7 +271,7 @@
    */
   public void addShutdownHook(Thread hook)
   {
-    SecurityManager sm = securityManager; // Be thread-safe!
+    SecurityManager sm = SecurityManager.current; // Be thread-safe!
     if (sm != null)
       sm.checkPermission(new RuntimePermission("shutdownHooks"));
     if (hook.isAlive() || hook.getThreadGroup() == null)
@@ -313,7 +305,7 @@
    */
   public boolean removeShutdownHook(Thread hook)
   {
-    SecurityManager sm = securityManager; // Be thread-safe!
+    SecurityManager sm = SecurityManager.current; // Be thread-safe!
     if (sm != null)
       sm.checkPermission(new RuntimePermission("shutdownHooks"));
     synchronized (libpath)
@@ -340,7 +332,7 @@
    */
   public void halt(int status)
   {
-    SecurityManager sm = securityManager; // Be thread-safe!
+    SecurityManager sm = SecurityManager.current; // Be thread-safe!
     if (sm != null)
       sm.checkExit(status);
     exitInternal(status);
@@ -364,7 +356,7 @@
    */
   public static void runFinalizersOnExit(boolean finalizeOnExit)
   {
-    SecurityManager sm = securityManager; // Be thread-safe!
+    SecurityManager sm = SecurityManager.current; // Be thread-safe!
     if (sm != null)
       sm.checkExit(0);
     current.finalizeOnExit = finalizeOnExit;
@@ -494,7 +486,7 @@
   public Process exec(String[] cmd, String[] env, File dir)
     throws IOException
   {
-    SecurityManager sm = securityManager; // Be thread-safe!
+    SecurityManager sm = SecurityManager.current; // Be thread-safe!
     if (sm != null)
       sm.checkExec(cmd[0]);
     return execInternal(cmd, env, dir);
@@ -581,7 +573,7 @@
    */
   public void load(String filename)
   {
-    SecurityManager sm = securityManager; // Be thread-safe!
+    SecurityManager sm = SecurityManager.current; // Be thread-safe!
     if (sm != null)
       sm.checkLink(filename);
     _load(filename, false);
@@ -611,7 +603,7 @@
   {
     // This is different from the Classpath implementation, but I
     // believe it is more correct.
-    SecurityManager sm = securityManager; // Be thread-safe!
+    SecurityManager sm = SecurityManager.current; // Be thread-safe!
     if (sm != null)
       sm.checkLink(libname);
     _load(libname, true);
Index: java/lang/SecurityManager.java
===================================================================
RCS file: /cvs/gcc/gcc/libjava/java/lang/SecurityManager.java,v
retrieving revision 1.14
diff -u -r1.14 SecurityManager.java
--- java/lang/SecurityManager.java	21 Mar 2005 14:50:14 -0000	1.14
+++ java/lang/SecurityManager.java	25 Apr 2005 20:34:51 -0000
@@ -126,6 +126,14 @@
 public class SecurityManager
 {
   /**
+   * The current security manager. This is located here instead of in
+   * System, to avoid security problems, as well as bootstrap issues.
+   * Make sure to access it in a thread-safe manner; it is package visible
+   * to avoid overhead in java.lang.
+   */
+  static volatile SecurityManager current;
+
+  /**
    * Tells whether or not the SecurityManager is currently performing a
    * security check.
    * @deprecated Use {@link #checkPermission(Permission)} instead.
Index: java/lang/System.java
===================================================================
RCS file: /cvs/gcc/gcc/libjava/java/lang/System.java,v
retrieving revision 1.23
diff -u -r1.23 System.java
--- java/lang/System.java	25 Apr 2005 19:48:35 -0000	1.23
+++ java/lang/System.java	25 Apr 2005 20:34:51 -0000
@@ -120,7 +120,7 @@
    */
   public static void setIn(InputStream in)
   {
-    SecurityManager sm = Runtime.securityManager; // Be thread-safe.
+    SecurityManager sm = SecurityManager.current; // Be thread-safe.
     if (sm != null)
       sm.checkPermission(new RuntimePermission("setIO"));
     setIn0(in);
@@ -137,7 +137,7 @@
    */
   public static void setOut(PrintStream out)
   {
-    SecurityManager sm = Runtime.securityManager; // Be thread-safe.
+    SecurityManager sm = SecurityManager.current; // Be thread-safe.
     if (sm != null)
       sm.checkPermission(new RuntimePermission("setIO"));
     
@@ -155,7 +155,7 @@
    */
   public static void setErr(PrintStream err)
   {
-    SecurityManager sm = Runtime.securityManager; // Be thread-safe.
+    SecurityManager sm = SecurityManager.current; // Be thread-safe.
     if (sm != null)
       sm.checkPermission(new RuntimePermission("setIO"));
     setErr0(err);
@@ -180,10 +180,10 @@
     // Implementation note: the field lives in Runtime because of bootstrap
     // initialization issues. This method is synchronized so that no other
     // thread changes it to null before this thread makes the change.
-    if (Runtime.securityManager != null)
-      Runtime.securityManager.checkPermission
+    if (SecurityManager.current != null)
+      SecurityManager.current.checkPermission
         (new RuntimePermission("setSecurityManager"));
-    Runtime.securityManager = sm;
+    SecurityManager.current = sm;
   }
 
   /**
@@ -196,7 +196,7 @@
   {
     // Implementation note: the field lives in Runtime because of bootstrap
     // initialization issues.
-    return Runtime.securityManager;
+    return SecurityManager.current;
   }
 
   /**
@@ -309,7 +309,7 @@
    */
   public static Properties getProperties()
   {
-    SecurityManager sm = Runtime.securityManager; // Be thread-safe.
+    SecurityManager sm = SecurityManager.current; // Be thread-safe.
     if (sm != null)
       sm.checkPropertiesAccess();
     return SystemProperties.getProperties();
@@ -326,7 +326,7 @@
    */
   public static void setProperties(Properties properties)
   {
-    SecurityManager sm = Runtime.securityManager; // Be thread-safe.
+    SecurityManager sm = SecurityManager.current; // Be thread-safe.
     if (sm != null)
       sm.checkPropertiesAccess();
     SystemProperties.setProperties(properties);
@@ -344,7 +344,7 @@
    */
   public static String getProperty(String key)
   {
-    SecurityManager sm = Runtime.securityManager; // Be thread-safe.
+    SecurityManager sm = SecurityManager.current; // Be thread-safe.
     if (sm != null)
       sm.checkPropertyAccess(key);
     else if (key.length() == 0)
@@ -365,7 +365,7 @@
    */
   public static String getProperty(String key, String def)
   {
-    SecurityManager sm = Runtime.securityManager; // Be thread-safe.
+    SecurityManager sm = SecurityManager.current; // Be thread-safe.
     if (sm != null)
       sm.checkPropertyAccess(key);
     return SystemProperties.getProperty(key, def);
@@ -385,7 +385,7 @@
    */
   public static String setProperty(String key, String value)
   {
-    SecurityManager sm = Runtime.securityManager; // Be thread-safe.
+    SecurityManager sm = SecurityManager.current; // Be thread-safe.
     if (sm != null)
       sm.checkPermission(new PropertyPermission(key, "write"));
     return SystemProperties.setProperty(key, value);
@@ -407,7 +407,7 @@
   {
     if (name == null)
       throw new NullPointerException();
-    SecurityManager sm = Runtime.securityManager; // Be thread-safe.
+    SecurityManager sm = SecurityManager.current; // Be thread-safe.
     if (sm != null)
       sm.checkPermission(new RuntimePermission("getenv." + name));
     return getenv0(name);
Index: java/lang/ThreadGroup.java
===================================================================
RCS file: /cvs/gcc/gcc/libjava/java/lang/ThreadGroup.java,v
retrieving revision 1.20
diff -u -r1.20 ThreadGroup.java
--- java/lang/ThreadGroup.java	17 Feb 2005 07:48:34 -0000	1.20
+++ java/lang/ThreadGroup.java	25 Apr 2005 20:34:51 -0000
@@ -263,7 +263,7 @@
   public final void checkAccess()
   {
     // Bypass System.getSecurityManager, for bootstrap efficiency.
-    SecurityManager sm = Runtime.securityManager;
+    SecurityManager sm = SecurityManager.current;
     if (sm != null)
       sm.checkAccess(this);
   }


More information about the Java-patches mailing list