diff --git a/jdk/src/java.prefs/share/classes/java/util/prefs/AbstractPreferences.java b/jdk/src/java.prefs/share/classes/java/util/prefs/AbstractPreferences.java index fd3ba69902a..970aa19816d 100644 --- a/jdk/src/java.prefs/share/classes/java/util/prefs/AbstractPreferences.java +++ b/jdk/src/java.prefs/share/classes/java/util/prefs/AbstractPreferences.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2000, 2013, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2000, 2015, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -78,10 +78,9 @@ import java.lang.Double; * under which these calls cannot even enqueue the requested operation for * later processing. Even under these circumstances it is generally better to * simply ignore the invocation and return, rather than throwing an - * exception. Under these circumstances, however, all subsequent invocations - * of flush() and sync should return false, as - * returning true would imply that all previous operations had - * successfully been made permanent. + * exception. Under these circumstances, however, subsequently invoking + * flush() or sync would not imply that all previous + * operations had successfully been made permanent. * *
There is one circumstance under which putSpi, removeSpi and
* childSpi should throw an exception: if the caller lacks
@@ -122,6 +121,13 @@ import java.lang.Double;
* @since 1.4
*/
public abstract class AbstractPreferences extends Preferences {
+ /**
+ * The code point U+0000, assigned to the null control character, is the
+ * only character encoded in Unicode and ISO/IEC 10646 that is always
+ * invalid in any XML 1.0 and 1.1 document.
+ */
+ static final int CODE_POINT_U0000 = '\u0000';
+
/**
* Our name relative to parent.
*/
@@ -234,6 +240,8 @@ public abstract class AbstractPreferences extends Preferences {
* @throws IllegalArgumentException if key.length() exceeds
* MAX_KEY_LENGTH or if value.length exceeds
* MAX_VALUE_LENGTH.
+ * @throws IllegalArgumentException if either key or value contain
+ * the null control character, code point U+0000.
* @throws IllegalStateException if this node (or an ancestor) has been
* removed with the {@link #removeNode()} method.
*/
@@ -244,6 +252,10 @@ public abstract class AbstractPreferences extends Preferences {
throw new IllegalArgumentException("Key too long: "+key);
if (value.length() > MAX_VALUE_LENGTH)
throw new IllegalArgumentException("Value too long: "+value);
+ if (key.indexOf(CODE_POINT_U0000) != -1)
+ throw new IllegalArgumentException("Key contains code point U+0000");
+ if (value.indexOf(CODE_POINT_U0000) != -1)
+ throw new IllegalArgumentException("Value contains code point U+0000");
synchronized(lock) {
if (removed)
@@ -275,10 +287,14 @@ public abstract class AbstractPreferences extends Preferences {
* removed with the {@link #removeNode()} method.
* @throws NullPointerException if key is null. (A
* null default is permitted.)
+ * @throws IllegalArgumentException if key contains the null control
+ * character, code point U+0000.
*/
public String get(String key, String def) {
if (key==null)
throw new NullPointerException("Null key");
+ if (key.indexOf(CODE_POINT_U0000) != -1)
+ throw new IllegalArgumentException("Key contains code point U+0000");
synchronized(lock) {
if (removed)
throw new IllegalStateException("Node has been removed.");
@@ -306,10 +322,14 @@ public abstract class AbstractPreferences extends Preferences {
* @param key key whose mapping is to be removed from the preference node.
* @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.
* @throws NullPointerException {@inheritDoc}.
*/
public void remove(String key) {
Objects.requireNonNull(key, "Specified key cannot be null");
+ if (key.indexOf(CODE_POINT_U0000) != -1)
+ throw new IllegalArgumentException("Key contains code point U+0000");
synchronized(lock) {
if (removed)
throw new IllegalStateException("Node has been removed.");
@@ -353,6 +373,8 @@ public abstract class AbstractPreferences extends Preferences {
* @throws NullPointerException if key is null.
* @throws IllegalArgumentException if key.length() exceeds
* MAX_KEY_LENGTH.
+ * @throws IllegalArgumentException if key contains
+ * the null control character, code point U+0000.
* @throws IllegalStateException if this node (or an ancestor) has been
* removed with the {@link #removeNode()} method.
*/
@@ -381,6 +403,8 @@ public abstract class AbstractPreferences extends Preferences {
* @throws IllegalStateException if this node (or an ancestor) has been
* removed with the {@link #removeNode()} method.
* @throws NullPointerException if key is null.
+ * @throws IllegalArgumentException if key contains the null control
+ * character, code point U+0000.
*/
public int getInt(String key, int def) {
int result = def;
@@ -408,6 +432,8 @@ public abstract class AbstractPreferences extends Preferences {
* @throws NullPointerException if key is null.
* @throws IllegalArgumentException if key.length() exceeds
* MAX_KEY_LENGTH.
+ * @throws IllegalArgumentException if key contains
+ * the null control character, code point U+0000.
* @throws IllegalStateException if this node (or an ancestor) has been
* removed with the {@link #removeNode()} method.
*/
@@ -436,6 +462,8 @@ public abstract class AbstractPreferences extends Preferences {
* @throws IllegalStateException if this node (or an ancestor) has been
* removed with the {@link #removeNode()} method.
* @throws NullPointerException if key is null.
+ * @throws IllegalArgumentException if key contains the null control
+ * character, code point U+0000.
*/
public long getLong(String key, long def) {
long result = def;
@@ -463,6 +491,8 @@ public abstract class AbstractPreferences extends Preferences {
* @throws NullPointerException if key is null.
* @throws IllegalArgumentException if key.length() exceeds
* MAX_KEY_LENGTH.
+ * @throws IllegalArgumentException if key contains
+ * the null control character, code point U+0000.
* @throws IllegalStateException if this node (or an ancestor) has been
* removed with the {@link #removeNode()} method.
*/
@@ -494,6 +524,8 @@ public abstract class AbstractPreferences extends Preferences {
* @throws IllegalStateException if this node (or an ancestor) has been
* removed with the {@link #removeNode()} method.
* @throws NullPointerException if key is null.
+ * @throws IllegalArgumentException if key contains the null control
+ * character, code point U+0000.
*/
public boolean getBoolean(String key, boolean def) {
boolean result = def;
@@ -521,6 +553,8 @@ public abstract class AbstractPreferences extends Preferences {
* @throws NullPointerException if key is null.
* @throws IllegalArgumentException if key.length() exceeds
* MAX_KEY_LENGTH.
+ * @throws IllegalArgumentException if key contains
+ * the null control character, code point U+0000.
* @throws IllegalStateException if this node (or an ancestor) has been
* removed with the {@link #removeNode()} method.
*/
@@ -549,6 +583,8 @@ public abstract class AbstractPreferences extends Preferences {
* @throws IllegalStateException if this node (or an ancestor) has been
* removed with the {@link #removeNode()} method.
* @throws NullPointerException if key is null.
+ * @throws IllegalArgumentException if key contains the null control
+ * character, code point U+0000.
*/
public float getFloat(String key, float def) {
float result = def;
@@ -576,6 +612,8 @@ public abstract class AbstractPreferences extends Preferences {
* @throws NullPointerException if key is null.
* @throws IllegalArgumentException if key.length() exceeds
* MAX_KEY_LENGTH.
+ * @throws IllegalArgumentException if key contains
+ * the null control character, code point U+0000.
* @throws IllegalStateException if this node (or an ancestor) has been
* removed with the {@link #removeNode()} method.
*/
@@ -604,6 +642,8 @@ public abstract class AbstractPreferences extends Preferences {
* @throws IllegalStateException if this node (or an ancestor) has been
* removed with the {@link #removeNode()} method.
* @throws NullPointerException if key is null.
+ * @throws IllegalArgumentException if key contains the null control
+ * character, code point U+0000.
*/
public double getDouble(String key, double def) {
double result = def;
@@ -627,6 +667,8 @@ public abstract class AbstractPreferences extends Preferences {
* @throws NullPointerException if key or value is null.
* @throws IllegalArgumentException if key.length() exceeds MAX_KEY_LENGTH
* or if value.length exceeds MAX_VALUE_LENGTH*3/4.
+ * @throws IllegalArgumentException if key contains
+ * the null control character, code point U+0000.
* @throws IllegalStateException if this node (or an ancestor) has been
* removed with the {@link #removeNode()} method.
*/
@@ -650,6 +692,8 @@ public abstract class AbstractPreferences extends Preferences {
* removed with the {@link #removeNode()} method.
* @throws NullPointerException if key is null. (A
* null value for def is permitted.)
+ * @throws IllegalArgumentException if key contains the null control
+ * character, code point U+0000.
*/
public byte[] getByteArray(String key, byte[] def) {
byte[] result = def;
diff --git a/jdk/src/java.prefs/share/classes/java/util/prefs/Preferences.java b/jdk/src/java.prefs/share/classes/java/util/prefs/Preferences.java
index beb0b0fa1a9..9edefc5affb 100644
--- a/jdk/src/java.prefs/share/classes/java/util/prefs/Preferences.java
+++ b/jdk/src/java.prefs/share/classes/java/util/prefs/Preferences.java
@@ -489,7 +489,7 @@ public abstract class Preferences {
* MAX_VALUE_LENGTH.
* @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);
@@ -514,6 +514,8 @@ public abstract class Preferences {
* removed with the {@link #removeNode()} method.
* @throws NullPointerException if key is null. (A
* null value for def is permitted.)
+ * @throws IllegalArgumentException if key contains the null control
+ * character, code point U+0000.
*/
public abstract String get(String key, String def);
@@ -530,6 +532,8 @@ public abstract class Preferences {
* @throws NullPointerException if key is null.
* @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);
@@ -566,6 +570,8 @@ public abstract class Preferences {
* MAX_KEY_LENGTH.
* @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);
@@ -597,6 +603,8 @@ public abstract class Preferences {
* @throws IllegalStateException if this node (or an ancestor) has been
* removed with the {@link #removeNode()} method.
* @throws NullPointerException if key is null.
+ * @throws IllegalArgumentException if key contains the null control
+ * character, code point U+0000.
* @see #putInt(String,int)
* @see #get(String,String)
*/
@@ -616,6 +624,8 @@ public abstract class Preferences {
* MAX_KEY_LENGTH.
* @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);
@@ -647,6 +657,8 @@ public abstract class Preferences {
* @throws IllegalStateException if this node (or an ancestor) has been
* removed with the {@link #removeNode()} method.
* @throws NullPointerException if key is null.
+ * @throws IllegalArgumentException if key contains the null control
+ * character, code point U+0000.
* @see #putLong(String,long)
* @see #get(String,String)
*/
@@ -666,6 +678,8 @@ public abstract class Preferences {
* MAX_KEY_LENGTH.
* @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)
*/
@@ -702,6 +716,8 @@ public abstract class Preferences {
* @throws IllegalStateException if this node (or an ancestor) has been
* removed with the {@link #removeNode()} method.
* @throws NullPointerException if key is null.
+ * @throws IllegalArgumentException if key contains the null control
+ * character, code point U+0000.
* @see #get(String,String)
* @see #putBoolean(String,boolean)
*/
@@ -721,6 +737,8 @@ public abstract class Preferences {
* MAX_KEY_LENGTH.
* @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);
@@ -751,6 +769,8 @@ public abstract class Preferences {
* @throws IllegalStateException if this node (or an ancestor) has been
* removed with the {@link #removeNode()} method.
* @throws NullPointerException if key is null.
+ * @throws IllegalArgumentException if key contains the null control
+ * character, code point U+0000.
* @see #putFloat(String,float)
* @see #get(String,String)
*/
@@ -770,6 +790,8 @@ public abstract class Preferences {
* MAX_KEY_LENGTH.
* @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);
@@ -800,6 +822,8 @@ public abstract class Preferences {
* @throws IllegalStateException if this node (or an ancestor) has been
* removed with the {@link #removeNode()} method.
* @throws NullPointerException if key is null.
+ * @throws IllegalArgumentException if key contains the null control
+ * character, code point U+0000.
* @see #putDouble(String,double)
* @see #get(String,String)
*/
@@ -825,6 +849,8 @@ public abstract class Preferences {
* 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)
*/
@@ -864,6 +890,8 @@ public abstract class Preferences {
* removed with the {@link #removeNode()} method.
* @throws NullPointerException if key is null. (A
* null value for def is permitted.)
+ * @throws IllegalArgumentException if key contains the null control
+ * character, code point U+0000.
* @see #get(String,String)
* @see #putByteArray(String,byte[])
*/
diff --git a/jdk/src/java.prefs/unix/classes/java/util/prefs/FileSystemPreferences.java b/jdk/src/java.prefs/unix/classes/java/util/prefs/FileSystemPreferences.java
index 9d412ed7f67..10188cc98c5 100644
--- a/jdk/src/java.prefs/unix/classes/java/util/prefs/FileSystemPreferences.java
+++ b/jdk/src/java.prefs/unix/classes/java/util/prefs/FileSystemPreferences.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2000, 2015, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2000, 2011, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@@ -49,13 +49,6 @@ import sun.util.logging.PlatformLogger;
*/
class FileSystemPreferences extends AbstractPreferences {
- /**
- * The code point U+0000, assigned to the null control character, is the
- * only character encoded in Unicode and ISO/IEC 10646 that is always
- * invalid in any XML 1.0 and 1.1 document.
- */
- private static final String CODE_POINT_U0000 = String.valueOf('\u0000');
-
static {
PrivilegedAction