Commit 4b30c6bd by Michael Koch Committed by Michael Koch

Runtime.java, [...]: Replaced java.lang.Runtime.securityManager by…

Runtime.java, [...]: Replaced java.lang.Runtime.securityManager by java.lang.SecurityManager.current...

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).

From-SVN: r98738
parent 1f4ea3f2
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).
2005-04-25 David Gilbert <david.gilbert@object-refinery.com> 2005-04-25 David Gilbert <david.gilbert@object-refinery.com>
* java/awt/Transparency.java * java/awt/Transparency.java
......
...@@ -65,14 +65,6 @@ public class Runtime ...@@ -65,14 +65,6 @@ public class Runtime
*/ */
private final String[] libpath; 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 static
{ {
init(); init();
...@@ -151,7 +143,7 @@ public class Runtime ...@@ -151,7 +143,7 @@ public class Runtime
*/ */
public void exit(int status) public void exit(int status)
{ {
SecurityManager sm = securityManager; // Be thread-safe! SecurityManager sm = SecurityManager.current; // Be thread-safe!
if (sm != null) if (sm != null)
sm.checkExit(status); sm.checkExit(status);
boolean first = false; boolean first = false;
...@@ -279,7 +271,7 @@ public class Runtime ...@@ -279,7 +271,7 @@ public class Runtime
*/ */
public void addShutdownHook(Thread hook) public void addShutdownHook(Thread hook)
{ {
SecurityManager sm = securityManager; // Be thread-safe! SecurityManager sm = SecurityManager.current; // Be thread-safe!
if (sm != null) if (sm != null)
sm.checkPermission(new RuntimePermission("shutdownHooks")); sm.checkPermission(new RuntimePermission("shutdownHooks"));
if (hook.isAlive() || hook.getThreadGroup() == null) if (hook.isAlive() || hook.getThreadGroup() == null)
...@@ -313,7 +305,7 @@ public class Runtime ...@@ -313,7 +305,7 @@ public class Runtime
*/ */
public boolean removeShutdownHook(Thread hook) public boolean removeShutdownHook(Thread hook)
{ {
SecurityManager sm = securityManager; // Be thread-safe! SecurityManager sm = SecurityManager.current; // Be thread-safe!
if (sm != null) if (sm != null)
sm.checkPermission(new RuntimePermission("shutdownHooks")); sm.checkPermission(new RuntimePermission("shutdownHooks"));
synchronized (libpath) synchronized (libpath)
...@@ -340,7 +332,7 @@ public class Runtime ...@@ -340,7 +332,7 @@ public class Runtime
*/ */
public void halt(int status) public void halt(int status)
{ {
SecurityManager sm = securityManager; // Be thread-safe! SecurityManager sm = SecurityManager.current; // Be thread-safe!
if (sm != null) if (sm != null)
sm.checkExit(status); sm.checkExit(status);
exitInternal(status); exitInternal(status);
...@@ -364,7 +356,7 @@ public class Runtime ...@@ -364,7 +356,7 @@ public class Runtime
*/ */
public static void runFinalizersOnExit(boolean finalizeOnExit) public static void runFinalizersOnExit(boolean finalizeOnExit)
{ {
SecurityManager sm = securityManager; // Be thread-safe! SecurityManager sm = SecurityManager.current; // Be thread-safe!
if (sm != null) if (sm != null)
sm.checkExit(0); sm.checkExit(0);
current.finalizeOnExit = finalizeOnExit; current.finalizeOnExit = finalizeOnExit;
...@@ -494,7 +486,7 @@ public class Runtime ...@@ -494,7 +486,7 @@ public class Runtime
public Process exec(String[] cmd, String[] env, File dir) public Process exec(String[] cmd, String[] env, File dir)
throws IOException throws IOException
{ {
SecurityManager sm = securityManager; // Be thread-safe! SecurityManager sm = SecurityManager.current; // Be thread-safe!
if (sm != null) if (sm != null)
sm.checkExec(cmd[0]); sm.checkExec(cmd[0]);
return execInternal(cmd, env, dir); return execInternal(cmd, env, dir);
...@@ -581,7 +573,7 @@ public class Runtime ...@@ -581,7 +573,7 @@ public class Runtime
*/ */
public void load(String filename) public void load(String filename)
{ {
SecurityManager sm = securityManager; // Be thread-safe! SecurityManager sm = SecurityManager.current; // Be thread-safe!
if (sm != null) if (sm != null)
sm.checkLink(filename); sm.checkLink(filename);
_load(filename, false); _load(filename, false);
...@@ -611,7 +603,7 @@ public class Runtime ...@@ -611,7 +603,7 @@ public class Runtime
{ {
// This is different from the Classpath implementation, but I // This is different from the Classpath implementation, but I
// believe it is more correct. // believe it is more correct.
SecurityManager sm = securityManager; // Be thread-safe! SecurityManager sm = SecurityManager.current; // Be thread-safe!
if (sm != null) if (sm != null)
sm.checkLink(libname); sm.checkLink(libname);
_load(libname, true); _load(libname, true);
......
...@@ -126,6 +126,14 @@ import java.util.PropertyPermission; ...@@ -126,6 +126,14 @@ import java.util.PropertyPermission;
public class SecurityManager 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 * Tells whether or not the SecurityManager is currently performing a
* security check. * security check.
* @deprecated Use {@link #checkPermission(Permission)} instead. * @deprecated Use {@link #checkPermission(Permission)} instead.
......
...@@ -120,7 +120,7 @@ public final class System ...@@ -120,7 +120,7 @@ public final class System
*/ */
public static void setIn(InputStream in) public static void setIn(InputStream in)
{ {
SecurityManager sm = Runtime.securityManager; // Be thread-safe. SecurityManager sm = SecurityManager.current; // Be thread-safe.
if (sm != null) if (sm != null)
sm.checkPermission(new RuntimePermission("setIO")); sm.checkPermission(new RuntimePermission("setIO"));
setIn0(in); setIn0(in);
...@@ -137,7 +137,7 @@ public final class System ...@@ -137,7 +137,7 @@ public final class System
*/ */
public static void setOut(PrintStream out) public static void setOut(PrintStream out)
{ {
SecurityManager sm = Runtime.securityManager; // Be thread-safe. SecurityManager sm = SecurityManager.current; // Be thread-safe.
if (sm != null) if (sm != null)
sm.checkPermission(new RuntimePermission("setIO")); sm.checkPermission(new RuntimePermission("setIO"));
...@@ -155,7 +155,7 @@ public final class System ...@@ -155,7 +155,7 @@ public final class System
*/ */
public static void setErr(PrintStream err) public static void setErr(PrintStream err)
{ {
SecurityManager sm = Runtime.securityManager; // Be thread-safe. SecurityManager sm = SecurityManager.current; // Be thread-safe.
if (sm != null) if (sm != null)
sm.checkPermission(new RuntimePermission("setIO")); sm.checkPermission(new RuntimePermission("setIO"));
setErr0(err); setErr0(err);
...@@ -180,10 +180,10 @@ public final class System ...@@ -180,10 +180,10 @@ public final class System
// Implementation note: the field lives in Runtime because of bootstrap // Implementation note: the field lives in Runtime because of bootstrap
// initialization issues. This method is synchronized so that no other // initialization issues. This method is synchronized so that no other
// thread changes it to null before this thread makes the change. // thread changes it to null before this thread makes the change.
if (Runtime.securityManager != null) if (SecurityManager.current != null)
Runtime.securityManager.checkPermission SecurityManager.current.checkPermission
(new RuntimePermission("setSecurityManager")); (new RuntimePermission("setSecurityManager"));
Runtime.securityManager = sm; SecurityManager.current = sm;
} }
/** /**
...@@ -196,7 +196,7 @@ public final class System ...@@ -196,7 +196,7 @@ public final class System
{ {
// Implementation note: the field lives in Runtime because of bootstrap // Implementation note: the field lives in Runtime because of bootstrap
// initialization issues. // initialization issues.
return Runtime.securityManager; return SecurityManager.current;
} }
/** /**
...@@ -309,7 +309,7 @@ public final class System ...@@ -309,7 +309,7 @@ public final class System
*/ */
public static Properties getProperties() public static Properties getProperties()
{ {
SecurityManager sm = Runtime.securityManager; // Be thread-safe. SecurityManager sm = SecurityManager.current; // Be thread-safe.
if (sm != null) if (sm != null)
sm.checkPropertiesAccess(); sm.checkPropertiesAccess();
return SystemProperties.getProperties(); return SystemProperties.getProperties();
...@@ -326,7 +326,7 @@ public final class System ...@@ -326,7 +326,7 @@ public final class System
*/ */
public static void setProperties(Properties properties) public static void setProperties(Properties properties)
{ {
SecurityManager sm = Runtime.securityManager; // Be thread-safe. SecurityManager sm = SecurityManager.current; // Be thread-safe.
if (sm != null) if (sm != null)
sm.checkPropertiesAccess(); sm.checkPropertiesAccess();
SystemProperties.setProperties(properties); SystemProperties.setProperties(properties);
...@@ -344,7 +344,7 @@ public final class System ...@@ -344,7 +344,7 @@ public final class System
*/ */
public static String getProperty(String key) public static String getProperty(String key)
{ {
SecurityManager sm = Runtime.securityManager; // Be thread-safe. SecurityManager sm = SecurityManager.current; // Be thread-safe.
if (sm != null) if (sm != null)
sm.checkPropertyAccess(key); sm.checkPropertyAccess(key);
else if (key.length() == 0) else if (key.length() == 0)
...@@ -365,7 +365,7 @@ public final class System ...@@ -365,7 +365,7 @@ public final class System
*/ */
public static String getProperty(String key, String def) 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) if (sm != null)
sm.checkPropertyAccess(key); sm.checkPropertyAccess(key);
return SystemProperties.getProperty(key, def); return SystemProperties.getProperty(key, def);
...@@ -385,7 +385,7 @@ public final class System ...@@ -385,7 +385,7 @@ public final class System
*/ */
public static String setProperty(String key, String value) 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) if (sm != null)
sm.checkPermission(new PropertyPermission(key, "write")); sm.checkPermission(new PropertyPermission(key, "write"));
return SystemProperties.setProperty(key, value); return SystemProperties.setProperty(key, value);
...@@ -407,7 +407,7 @@ public final class System ...@@ -407,7 +407,7 @@ public final class System
{ {
if (name == null) if (name == null)
throw new NullPointerException(); throw new NullPointerException();
SecurityManager sm = Runtime.securityManager; // Be thread-safe. SecurityManager sm = SecurityManager.current; // Be thread-safe.
if (sm != null) if (sm != null)
sm.checkPermission(new RuntimePermission("getenv." + name)); sm.checkPermission(new RuntimePermission("getenv." + name));
return getenv0(name); return getenv0(name);
......
...@@ -263,7 +263,7 @@ public class ThreadGroup ...@@ -263,7 +263,7 @@ public class ThreadGroup
public final void checkAccess() public final void checkAccess()
{ {
// Bypass System.getSecurityManager, for bootstrap efficiency. // Bypass System.getSecurityManager, for bootstrap efficiency.
SecurityManager sm = Runtime.securityManager; SecurityManager sm = SecurityManager.current;
if (sm != null) if (sm != null)
sm.checkAccess(this); sm.checkAccess(this);
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment