summaryrefslogtreecommitdiff
path: root/java/lang/System.java
diff options
context:
space:
mode:
authorTom Tromey <tromey@redhat.com>2006-03-07 22:21:00 +0000
committerTom Tromey <tromey@redhat.com>2006-03-07 22:21:00 +0000
commitd388d065b2a4563325e99272db487492ad252e99 (patch)
tree13ca33dd1fb7b27fcc76f25ba06ca3ca113039d2 /java/lang/System.java
parentfa8239b8eecc556b46b03b789975f97d441833c5 (diff)
downloadclasspath-d388d065b2a4563325e99272db487492ad252e99.tar.gz
* java/lang/System.java (clearProperty): New method, merged from
generics branch. (getProperty): Removed 'else'. (getProperty): Check for empty key. (setProperty): Likewise. * gnu/classpath/SystemProperties.java (remove): New method, merged from generics branch.
Diffstat (limited to 'java/lang/System.java')
-rw-r--r--java/lang/System.java33
1 files changed, 32 insertions, 1 deletions
diff --git a/java/lang/System.java b/java/lang/System.java
index 34bbfddc6..b538b795b 100644
--- a/java/lang/System.java
+++ b/java/lang/System.java
@@ -364,7 +364,7 @@ public final class System
SecurityManager sm = SecurityManager.current; // Be thread-safe.
if (sm != null)
sm.checkPropertyAccess(key);
- else if (key.length() == 0)
+ if (key.length() == 0)
throw new IllegalArgumentException("key can't be empty");
return SystemProperties.getProperty(key);
}
@@ -385,6 +385,10 @@ public final class System
SecurityManager sm = SecurityManager.current; // Be thread-safe.
if (sm != null)
sm.checkPropertyAccess(key);
+ // This handles both the null pointer exception and the illegal
+ // argument exception.
+ if (key.length() == 0)
+ throw new IllegalArgumentException("key can't be empty");
return SystemProperties.getProperty(key, def);
}
@@ -405,10 +409,37 @@ public final class System
SecurityManager sm = SecurityManager.current; // Be thread-safe.
if (sm != null)
sm.checkPermission(new PropertyPermission(key, "write"));
+ // This handles both the null pointer exception and the illegal
+ // argument exception.
+ if (key.length() == 0)
+ throw new IllegalArgumentException("key can't be empty");
return SystemProperties.setProperty(key, value);
}
/**
+ * Remove a single system property by name. A security check may be
+ * performed, <code>checkPropertyAccess(key, "write")</code>.
+ *
+ * @param key the name of the system property to remove
+ * @return the previous value, or null
+ * @throws SecurityException if permission is denied
+ * @throws NullPointerException if key is null
+ * @throws IllegalArgumentException if key is ""
+ * @since 1.5
+ */
+ public static String clearProperty(String key)
+ {
+ SecurityManager sm = SecurityManager.current; // Be thread-safe.
+ if (sm != null)
+ sm.checkPermission(new PropertyPermission(key, "write"));
+ // This handles both the null pointer exception and the illegal
+ // argument exception.
+ if (key.length() == 0)
+ throw new IllegalArgumentException("key can't be empty");
+ return SystemProperties.remove(key);
+ }
+
+ /**
* Gets the value of an environment variable.
*
* @param name the name of the environment variable