diff options
| author | Christopher Tate <ctate@google.com> | 2012-10-19 14:38:04 -0700 |
|---|---|---|
| committer | Android (Google) Code Review <android-gerrit@google.com> | 2012-10-19 14:38:05 -0700 |
| commit | 935415a050be75f582f632dd168be9fbb047137b (patch) | |
| tree | 825e2e2ec67e90bc044996d6d08f9bc5e37ccf0e /core/java/android | |
| parent | 6dad395ca8d5ff4ae278ac82a6de7a1ed2e36b49 (diff) | |
| parent | 01ed79c5786c527628544828abf8b70d02b989cd (diff) | |
| download | frameworks_base-935415a050be75f582f632dd168be9fbb047137b.zip frameworks_base-935415a050be75f582f632dd168be9fbb047137b.tar.gz frameworks_base-935415a050be75f582f632dd168be9fbb047137b.tar.bz2 | |
Merge "Document immutable requirement of SharedPreferences return objects" into jb-mr1-dev
Diffstat (limited to 'core/java/android')
| -rw-r--r-- | core/java/android/app/SharedPreferencesImpl.java | 3 | ||||
| -rw-r--r-- | core/java/android/content/SharedPreferences.java | 11 |
2 files changed, 12 insertions, 2 deletions
diff --git a/core/java/android/app/SharedPreferencesImpl.java b/core/java/android/app/SharedPreferencesImpl.java index 201d7b2..86fd7b9 100644 --- a/core/java/android/app/SharedPreferencesImpl.java +++ b/core/java/android/app/SharedPreferencesImpl.java @@ -312,7 +312,8 @@ final class SharedPreferencesImpl implements SharedPreferences { } public Editor putStringSet(String key, Set<String> values) { synchronized (this) { - mModified.put(key, values); + mModified.put(key, + (values == null) ? null : new HashSet<String>(values)); return this; } } diff --git a/core/java/android/content/SharedPreferences.java b/core/java/android/content/SharedPreferences.java index bdc38d6..da5480e 100644 --- a/core/java/android/content/SharedPreferences.java +++ b/core/java/android/content/SharedPreferences.java @@ -25,7 +25,8 @@ import java.util.Set; * there is a single instance of this class that all clients share. * Modifications to the preferences must go through an {@link Editor} object * to ensure the preference values remain in a consistent state and control - * when they are committed to storage. + * when they are committed to storage. Objects that are returned from the + * various <code>get</code> methods must be treated as immutable by the application. * * <p><em>Note: currently this class does not support use across multiple * processes. This will be added later.</em> @@ -226,6 +227,10 @@ public interface SharedPreferences { /** * Retrieve all values from the preferences. * + * <p>Note that you <em>must not</em> modify the collection returned + * by this method, or alter any of its contents. The consistency of your + * stored data is not guaranteed if you do. + * * @return Returns a map containing a list of pairs key/value representing * the preferences. * @@ -250,6 +255,10 @@ public interface SharedPreferences { /** * Retrieve a set of String values from the preferences. * + * <p>Note that you <em>must not</em> modify the set instance returned + * by this call. The consistency of the stored data is not guaranteed + * if you do, nor is your ability to modify the instance at all. + * * @param key The name of the preference to retrieve. * @param defValues Values to return if this preference does not exist. * |
