question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

NullPointerException when targeting devices running OS versions Android R or later

See original GitHub issue

Looks 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.

Please see: https://developer.android.com/reference/android/content/SharedPreferences.OnSharedPreferenceChangeListener#onSharedPreferenceChanged(android.content.SharedPreferences, java.lang.String)

Issue Analytics

  • State:open
  • Created 3 years ago
  • Comments:6 (4 by maintainers)

github_iconTop GitHub Comments

7reactions
davelogancommented, Sep 22, 2020

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)

3reactions
f2prateekcommented, Oct 1, 2020

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.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found