Assigned
Status Update
Comments
lb...@gmail.com <lb...@gmail.com> #2
My dependencies:
implementation 'androidx.appcompat:appcompat:1.4.0'
implementation 'androidx.preference:preference:1.1.1'
implementation 'com.google.android.gms:play-services-wearable:17.1.0'
implementation 'com.google.android.material:material:1.4.0'
If I remove androidx.appcompat:appcompat:1.4.0
, the warning vanishes, so I imagine there's some transitive dependency on an older version of androidx.appcompat:appcompat
that doesn't have the warning.
Description
I'd prefer to have null returned instead, and it seems the code behind could actually support it.
For example in the implementation of SharedPreferencesImpl:
@Override
public long getLong(String key, long defValue) {
synchronized (mLock) {
awaitLoadedLocked();
Long v = (Long)mMap.get(key);
return v != null ? v : defValue;
}
}
Or the implementation in EncryptedSharedPreferences:
@Override
public long getLong(@Nullable String key, long defValue) {
Object value = getDecryptedObject(key);
return (value != null && value instanceof Long ? (Long) value : defValue);
}
So, the "getDecryptedObject" could be null, and if it is null, the default value gets returned.
Please offer nullable result instead.
Maybe call each with "OrNull". Example: getLongOrNull.
Trying to implement this myself would not be atomic:
fun SharedPreferences.getLongOrNull(key:String):Long?{
if(!this.contains(key))
return null
return getLong(key,0)
}
The only good workaround for this would be to save each value as a String and parse from there.