Closed ypresto closed 9 years ago
Updated PR to include fix NPE on null default value.
Thank you for your Pull Request! I really appreciate it. Nevertheless, I would like to avoid passing null
as a parameters in the library. It's not recommended practice. The only exception is a situation in which Android API or native Java method allows to pass null
, but it's still not good. Moreover, removing values with put(...)
method may be confusing for some developers, which may expect null
value to be stored under a specified key. I'd like developers to explicitly use remove(...)
method when they want to remove some value.
If null
value was passed as a default value, NPE can occur and developer should be aware of that. SharedPreferences
in Android API have the same behavior. If you would like to avoid NPE, you should pass default value different than null
.
I see, you are right about test dependencies, which fixes execution of the unit tests, but unfortunately I cannot merge part of this PR and I've updated dependencies in a separate commit.
sharedPreferences.putString(key, null)
removes that key. This PR implements this in prefser. Also fixes that null default value for primitive data types (prefser.get(key, Integer.class, null)
) causes NPE. Thanks!