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 - Parameter specified as non-null is null (updatedKey)

See original GitHub issue

Hi, first of all, thanks for this awesome library, we are using in our KMM project, and its working great. We do have this issue that occurs on some devices, we have seen it on android 11 and 12, and not on android 10 and 9. Here is the stack trace

java.lang.NullPointerException: Parameter specified as non-null is null: method com.russhwolf.settings.AndroidSettings.addListener$lambda-1, parameter updatedKey
    at com.russhwolf.settings.AndroidSettings.addListener$lambda-1
    at com.russhwolf.settings.AndroidSettings.lambda$ejYPvc8UpZPLw0Pu9AuA51-Vbq8
    at com.russhwolf.settings.-$$Lambda$AndroidSettings$ejYPvc8UpZPLw0Pu9AuA51-Vbq8.onSharedPreferenceChanged
    at android.app.SharedPreferencesImpl$EditorImpl.notifyListeners(SharedPreferencesImpl.java:629)
    at android.app.SharedPreferencesImpl$EditorImpl.lambda$notifyListeners$0$SharedPreferencesImpl$EditorImpl(SharedPreferencesImpl.java:643)
    at android.app.SharedPreferencesImpl$EditorImpl$$ExternalSyntheticLambda0.run
    at android.os.Handler.handleCallback(Handler.java:938)
    at android.os.Handler.dispatchMessage(Handler.java:99)
    at android.os.Looper.loopOnce(Looper.java:226)
    at android.os.Looper.loop(Looper.java:313)
    at android.app.ActivityThread.main(ActivityThread.java:8633)
    at java.lang.reflect.Method.invoke(Method.java)
    at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:567)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1133)

What’s strange is that we do not attach any listeners when we are creating the Settings class in our Koin setup. So I am puzzled about how and why is Android SharedPreferences calling notifyListeners.

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
russhwolfcommented, May 2, 2022

This is fixed in version 0.9

1reaction
russhwolfcommented, Apr 30, 2022

Oh scratch that, it should be rare because AndroidSettings.clear() doesn’t call clear() on the SharedPreferences, it calls remove() on every key instead. The only time you’ll see this issue is if you call preferences.edit().clear().apply() after setting listeners on AndroidSettings. So a better workaround is to call clear() on the Settings instead of the SharedPreferences.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Kotlin NullPointerException: Parameter specified as non- ...
In this quick tutorial, we're going to see what happens when we store a null value into a non-null data type in Kotlin....
Read more >
Parameter specified as non-null is null: method kotlin.jvm. ...
I'm getting this error. java.lang.IllegalArgumentException: Parameter specified as non-null is null ...
Read more >
"NullPointerException: Parameter specified as non-null is ...
Running into this exception when using Anvil 2.1.0 with @AssistedInject on Kotlin version 1.4.30 with useIR = true. Repro repository. Steps to reproduce:....
Read more >
Android Relations — How to avoid NullPointerException ...
Android Relations — How to avoid NullPointerException: Parameter specified as non-null is null. In this blog post I will discuss how to ...
Read more >
method kotlin.jvm.internal.Intrinsics.checkParam - YouTube
Android : Parameter specified as non-null is null : method kotlin.jvm.internal.Intrinsics.checkParameterIsNotNull, parameter convertView ...
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