Closed rjrjr closed 4 years ago
We're hitting this issue in code that I recently converted to RxSharedPreferences
. It's reading existing string values, and apparently some of them are null.
Should be able to fix this in RealPreference.get
, if we just stop relying on SharedPreferences.contains
.
Similar test as an addition to PreferenceTest
:
@Test public void legacyNullString() {
preferences.edit()
.putString("someString", null)
.commit();
assertThat(rxPreferences.getString("someString").get()).isEqualTo("");
}
StringAdapter
assumes that it will never read anull
fromSharedPreferences.getString
, which is not true. It enforces this invariant with anassert
, which is a no-op in most builds:SharedPreferences
is happy to record null values, and report that they have been set. For example, this test hits theassertion
above: