NullPointerException when targeting devices running OS versions Android R or later
See original GitHub issueLooks like there has been behavior change in OnSharedPreferenceChangeListener onSharedPreferenceChanged callback when apps target devices running OS versions Android R or later.
Now when preferences are cleared null
key will be received in onSharedPreferenceChanged which results in app crashing due to null value being emitted to rx stream.
Issue Analytics
- State:
- Created 3 years ago
- Comments:6 (4 by maintainers)
Top Results From Across the Web
NullPointerException - Android Developers
Returns an array containing all of the exceptions that were suppressed, typically by the try -with-resources statement, in order to deliver this exception....
Read more >android - NullPointerException on Meizu devices in Editor ...
My version (based on those solution and Google's fix): import android.os.Build import java.util.* import android.content.
Read more >Bug: NullPointerException: Resources.getConfiguration ...
It happened relatively recently, I can't find many old stack traces but I haven't looked very hard yet. It seems to affect mostly...
Read more >776223 - java.lang.NullPointerException: at android.content ...
Bugzilla · java.lang.NullPointerException: at android.content.ClipboardManager.setPrimaryClip(ClipboardManager.java) on Samsung devices running ICS.
Read more >Fix "java.lang.NullPointerException" in Android Studio
As you can observe from the above picture, it contains a Textview which is initialized to null. TextView textview = null;. The TextView ......
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
This is causing issues for my app as well after updating target version to 30.
Caused by: java.lang.NullPointerException: onNext called with null. Null values are generally not allowed in 2.x operators and sources. at io.reactivex.internal.operators.observable.ObservableCreate$CreateEmitter.onNext(ObservableCreate.java:62) at com.f2prateek.rx.preferences2.RxSharedPreferences$1$1.onSharedPreferenceChanged(RxSharedPreferences.java:44) at android.app.SharedPreferencesImpl$EditorImpl.notifyListeners(SharedPreferencesImpl.java:629) at android.app.SharedPreferencesImpl$EditorImpl.lambda$notifyListeners$0$SharedPreferencesImpl$EditorImpl(SharedPreferencesImpl.java:643)
The easy fix here would be to add a
null
check here. However this would result in no notification being fired when preferences are cleared, which would be less than ideal.I think we could also make it so that it emits the default value when this happens.