Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit c6f42900 authored by Narayan Kamath's avatar Narayan Kamath
Browse files

Fix preference puts with "null" values.

Null values were being written out as <null /> elements in the
XML prefs file (as expected). This allowed the getFoo() functions
to work correctly because they treated null values as missing mappings
but containsKey would fail.

bug: https://code.google.com/p/android/issues/detail?id=64563
Change-Id: I1f466d01db96bf26e208d4fed3a6f257228bea5d
parent 517e9b11
Loading
Loading
Loading
Loading
+4 −2
Original line number Diff line number Diff line
@@ -421,13 +421,15 @@ final class SharedPreferencesImpl implements SharedPreferences {
                    for (Map.Entry<String, Object> e : mModified.entrySet()) {
                        String k = e.getKey();
                        Object v = e.getValue();
                        if (v == this) {  // magic value for a removal mutation
                        // "this" is the magic value for a removal mutation. In addition,
                        // setting a value to "null" for a given key is specified to be
                        // equivalent to calling remove on that key.
                        if (v == this || v == null) {
                            if (!mMap.containsKey(k)) {
                                continue;
                            }
                            mMap.remove(k);
                        } else {
                            boolean isSame = false;
                            if (mMap.containsKey(k)) {
                                Object existingValue = mMap.get(k);
                                if (existingValue != null && existingValue.equals(v)) {