src/java.prefs/share/classes/java/util/prefs/Preferences.java

Print this page
rev 11736 : 8075156: (prefs) remove() should disallow the use of the null control character '\u0000' as key
Summary: Extend disallowing null control character key to remove()
Reviewed-by: XXX

@@ -487,11 +487,11 @@
      * @throws IllegalArgumentException if <tt>key.length()</tt> exceeds
      *       <tt>MAX_KEY_LENGTH</tt> or if <tt>value.length</tt> exceeds
      *       <tt>MAX_VALUE_LENGTH</tt>.
      * @throws IllegalStateException if this node (or an ancestor) has been
      *         removed with the {@link #removeNode()} method.
-     * @throws IllegalArgumentException if either the key or the value contain
+     * @throws IllegalArgumentException if either key or value contain
      *         the null control character, code point U+0000.
      */
     public abstract void put(String key, String value);
 
     /**

@@ -512,10 +512,12 @@
      *         store is inaccessible.
      * @throws IllegalStateException if this node (or an ancestor) has been
      *         removed with the {@link #removeNode()} method.
      * @throws NullPointerException if <tt>key</tt> is <tt>null</tt>.  (A
      *         <tt>null</tt> value for <tt>def</tt> <i>is</i> permitted.)
+     * @throws IllegalArgumentException if key contains the null control
+     *         character, code point U+0000.
      */
     public abstract String get(String key, String def);
 
     /**
      * Removes the value associated with the specified key in this preference

@@ -528,10 +530,12 @@
      *
      * @param key key whose mapping is to be removed from the preference node.
      * @throws NullPointerException if <tt>key</tt> is <tt>null</tt>.
      * @throws IllegalStateException if this node (or an ancestor) has been
      *         removed with the {@link #removeNode()} method.
+     * @throws IllegalArgumentException if key contains the null control
+     *         character, code point U+0000.
      */
     public abstract void remove(String key);
 
     /**
      * Removes all of the preferences (key-value associations) in this

@@ -564,10 +568,12 @@
      * @throws NullPointerException if <tt>key</tt> is <tt>null</tt>.
      * @throws IllegalArgumentException if <tt>key.length()</tt> exceeds
      *         <tt>MAX_KEY_LENGTH</tt>.
      * @throws IllegalStateException if this node (or an ancestor) has been
      *         removed with the {@link #removeNode()} method.
+     * @throws IllegalArgumentException if key contains
+     *         the null control character, code point U+0000.
      * @see #getInt(String,int)
      */
     public abstract void putInt(String key, int value);
 
     /**

@@ -595,10 +601,12 @@
      *         associated value does not exist or cannot be interpreted as
      *         an int.
      * @throws IllegalStateException if this node (or an ancestor) has been
      *         removed with the {@link #removeNode()} method.
      * @throws NullPointerException if <tt>key</tt> is <tt>null</tt>.
+     * @throws IllegalArgumentException if key contains the null control
+     *         character, code point U+0000.
      * @see #putInt(String,int)
      * @see #get(String,String)
      */
     public abstract int getInt(String key, int def);
 

@@ -614,10 +622,12 @@
      * @throws NullPointerException if <tt>key</tt> is <tt>null</tt>.
      * @throws IllegalArgumentException if <tt>key.length()</tt> exceeds
      *         <tt>MAX_KEY_LENGTH</tt>.
      * @throws IllegalStateException if this node (or an ancestor) has been
      *         removed with the {@link #removeNode()} method.
+     * @throws IllegalArgumentException if key contains
+     *         the null control character, code point U+0000.
      * @see #getLong(String,long)
      */
     public abstract void putLong(String key, long value);
 
     /**

@@ -645,10 +655,12 @@
      *         associated value does not exist or cannot be interpreted as
      *         a long.
      * @throws IllegalStateException if this node (or an ancestor) has been
      *         removed with the {@link #removeNode()} method.
      * @throws NullPointerException if <tt>key</tt> is <tt>null</tt>.
+     * @throws IllegalArgumentException if key contains the null control
+     *         character, code point U+0000.
      * @see #putLong(String,long)
      * @see #get(String,String)
      */
     public abstract long getLong(String key, long def);
 

@@ -664,10 +676,12 @@
      * @throws NullPointerException if <tt>key</tt> is <tt>null</tt>.
      * @throws IllegalArgumentException if <tt>key.length()</tt> exceeds
      *         <tt>MAX_KEY_LENGTH</tt>.
      * @throws IllegalStateException if this node (or an ancestor) has been
      *         removed with the {@link #removeNode()} method.
+     * @throws IllegalArgumentException if key contains
+     *         the null control character, code point U+0000.
      * @see #getBoolean(String,boolean)
      * @see #get(String,String)
      */
     public abstract void putBoolean(String key, boolean value);
 

@@ -700,10 +714,12 @@
      *         associated value does not exist or cannot be interpreted as
      *         a boolean.
      * @throws IllegalStateException if this node (or an ancestor) has been
      *         removed with the {@link #removeNode()} method.
      * @throws NullPointerException if <tt>key</tt> is <tt>null</tt>.
+     * @throws IllegalArgumentException if key contains the null control
+     *         character, code point U+0000.
      * @see #get(String,String)
      * @see #putBoolean(String,boolean)
      */
     public abstract boolean getBoolean(String key, boolean def);
 

@@ -719,10 +735,12 @@
      * @throws NullPointerException if <tt>key</tt> is <tt>null</tt>.
      * @throws IllegalArgumentException if <tt>key.length()</tt> exceeds
      *         <tt>MAX_KEY_LENGTH</tt>.
      * @throws IllegalStateException if this node (or an ancestor) has been
      *         removed with the {@link #removeNode()} method.
+     * @throws IllegalArgumentException if key contains
+     *         the null control character, code point U+0000.
      * @see #getFloat(String,float)
      */
     public abstract void putFloat(String key, float value);
 
     /**

@@ -749,10 +767,12 @@
      *         associated value does not exist or cannot be interpreted as
      *         a float.
      * @throws IllegalStateException if this node (or an ancestor) has been
      *         removed with the {@link #removeNode()} method.
      * @throws NullPointerException if <tt>key</tt> is <tt>null</tt>.
+     * @throws IllegalArgumentException if key contains the null control
+     *         character, code point U+0000.
      * @see #putFloat(String,float)
      * @see #get(String,String)
      */
     public abstract float getFloat(String key, float def);
 

@@ -768,10 +788,12 @@
      * @throws NullPointerException if <tt>key</tt> is <tt>null</tt>.
      * @throws IllegalArgumentException if <tt>key.length()</tt> exceeds
      *         <tt>MAX_KEY_LENGTH</tt>.
      * @throws IllegalStateException if this node (or an ancestor) has been
      *         removed with the {@link #removeNode()} method.
+     * @throws IllegalArgumentException if key contains
+     *         the null control character, code point U+0000.
      * @see #getDouble(String,double)
      */
     public abstract void putDouble(String key, double value);
 
     /**

@@ -798,10 +820,12 @@
      *         associated value does not exist or cannot be interpreted as
      *         a double.
      * @throws IllegalStateException if this node (or an ancestor) has been
      *         removed with the {@link #removeNode()} method.
      * @throws NullPointerException if <tt>key</tt> is <tt>null</tt>.
+     * @throws IllegalArgumentException if key contains the null control
+     *         character, code point U+0000.
      * @see #putDouble(String,double)
      * @see #get(String,String)
      */
     public abstract double getDouble(String key, double def);
 

@@ -823,10 +847,12 @@
      * @throws NullPointerException if key or value is <tt>null</tt>.
      * @throws IllegalArgumentException if key.length() exceeds MAX_KEY_LENGTH
      *         or if value.length exceeds MAX_VALUE_LENGTH*3/4.
      * @throws IllegalStateException if this node (or an ancestor) has been
      *         removed with the {@link #removeNode()} method.
+     * @throws IllegalArgumentException if key contains
+     *         the null control character, code point U+0000.
      * @see #getByteArray(String,byte[])
      * @see #get(String,String)
      */
     public abstract void putByteArray(String key, byte[] value);
 

@@ -862,10 +888,12 @@
      *         a byte array.
      * @throws IllegalStateException if this node (or an ancestor) has been
      *         removed with the {@link #removeNode()} method.
      * @throws NullPointerException if <tt>key</tt> is <tt>null</tt>.  (A
      *         <tt>null</tt> value for <tt>def</tt> <i>is</i> permitted.)
+     * @throws IllegalArgumentException if key contains the null control
+     *         character, code point U+0000.
      * @see #get(String,String)
      * @see #putByteArray(String,byte[])
      */
     public abstract byte[] getByteArray(String key, byte[] def);