jamesmontemagno / Xamarin.Plugins

Cross-platform Native API Access from Shared Code!
MIT License
1.3k stars 380 forks source link

Settings: AddOrUpdateValue<string>("key", null) adds an entry with empty string as the value, on Android. #285

Closed dvshub closed 8 years ago

dvshub commented 8 years ago

Please take a moment to fill out the following (change to preview to check or place x in []):

This is a

Which plugin does this impact:

Version Number of Plugin: 2.1.0 Device Tested On: Nexus 6P, Android version 6.0.1 Simulator Tested On: iPhone 6s, iOS version 9.2

Actual Behavior

On iOS: AddOrUpdateValue("key", null) throws ArgumentNullException. This is the same behavior as iOS's native NSUserDefaults.

On Android: AddOrUpdateValue("key", null) adds/updates the "key" with empty string as the value. This is different from the iOS behavior of this library, and also different from Android's native SharedPreferences behavior which actually removes the key if it was already present, or doesn't do anything otherwise.

Expected Behavior

To keep the behavior of the library consistent for all platforms, it should throw ArgumentNullException in this case. This will ensure that the application code relying on this library behaves the same way across all platforms. That is the whole purpose of using a cross-platform library in the first place.

Steps to reproduce the Behavior

Call Settings.AddOrUpdateValue("key", null);

This is related to https://github.com/jamesmontemagno/Xamarin.Plugins/issues/195 as the root cause of both is same.

jamesmontemagno commented 8 years ago

This issue was moved to jamesmontemagno/SettingsPlugin#5