classpath-patches
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[cp-patches] [generics] Patch: FYI: System and Properties


From: Tom Tromey
Subject: [cp-patches] [generics] Patch: FYI: System and Properties
Date: 09 Oct 2004 17:30:47 -0600

I'm checking this in on the generics branch.
This updates System and Properties a little.
There are new methods in both which I haven't yet looked at.

Tom

Index: ChangeLog
from  Tom Tromey  <address@hidden>
        * java/util/Properties.java: Extend Hashtable<Object, Object>.
        (save): Mark as @Deprecated.
        * java/lang/System.java (clearProperty): New method.
        (setProperty): Check for empty key.
        (getProperty): Likewise.

Index: java/lang/System.java
===================================================================
RCS file: /cvsroot/classpath/classpath/java/lang/System.java,v
retrieving revision 1.38
diff -u -r1.38 System.java
--- java/lang/System.java 23 Jul 2004 11:40:05 -0000 1.38
+++ java/lang/System.java 9 Oct 2004 23:32:39 -0000
@@ -557,6 +557,10 @@
    */
   public static String getProperty(String key, String def)
   {
+    // This handles both the null pointer exception and the illegal
+    // argument exception.
+    if (key.equals(""))
+      throw new IllegalArgumentException("empty key");
     SecurityManager sm = Runtime.securityManager; // Be thread-safe.
     if (sm != null)
       sm.checkPropertyAccess(key);
@@ -577,6 +581,10 @@
    */
   public static String setProperty(String key, String value)
   {
+    // This handles both the null pointer exception and the illegal
+    // argument exception.
+    if (key.equals(""))
+      throw new IllegalArgumentException("empty key");
     SecurityManager sm = Runtime.securityManager; // Be thread-safe.
     if (sm != null)
       sm.checkPermission(new PropertyPermission(key, "write"));
@@ -584,6 +592,29 @@
   }
 
   /**
+   * 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)
+  {
+    // This handles both the null pointer exception and the illegal
+    // argument exception.
+    if (key.equals(""))
+      throw new IllegalArgumentException("empty key");
+    SecurityManager sm = Runtime.securityManager; // Be thread-safe.
+    if (sm != null)
+      sm.checkPermission(new PropertyPermission(key, "write"));
+    return (String) properties.remove(key);
+  }
+
+  /**
    * This used to get an environment variable, but following Sun's lead,
    * it now throws an Error. Use <code>getProperty</code> instead.
    *
Index: java/util/Properties.java
===================================================================
RCS file: /cvsroot/classpath/classpath/java/util/Properties.java,v
retrieving revision 1.26
diff -u -r1.26 Properties.java
--- java/util/Properties.java 22 Apr 2004 11:24:39 -0000 1.26
+++ java/util/Properties.java 9 Oct 2004 23:32:39 -0000
@@ -90,7 +90,7 @@
  * @see PropertyResourceBundle
  * @status updated to 1.4
  */
-public class Properties extends Hashtable
+public class Properties extends Hashtable<Object, Object>
 {
   // WARNING: Properties is a CORE class in the bootstrap cycle. See the
   // comments in vm/reference/java/lang/Runtime for implications of this fact.
@@ -332,6 +332,7 @@
    *         value that are not strings
    * @deprecated use address@hidden #store(OutputStream, String)} instead
    */
+  @Deprecated
   public void save(OutputStream out, String header)
   {
     try
@@ -448,7 +449,7 @@
    *
    * @return an Enumeration of all defined keys
    */
-  public Enumeration propertyNames()
+  public Enumeration<?> propertyNames()
   {
     // We make a new Set that holds all the keys, then return an enumeration
     // for that. This prevents modifications from ruining the enumeration,




reply via email to

[Prev in Thread] Current Thread [Next in Thread]