Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NullPointerException - LifecycleRegistry.removeObserver #1776

Closed
sregg opened this issue May 30, 2023 · 22 comments
Closed

NullPointerException - LifecycleRegistry.removeObserver #1776

sregg opened this issue May 30, 2023 · 22 comments
Labels
Missing repro This issue need minimum repro scenario Platform: Android This issue is specific to Android

Comments

@sregg
Copy link

sregg commented May 30, 2023

Description

We're getting a few NPE in our app in prod.

NullPointerException
Parameter specified as non-null is null: method androidx.lifecycle.LifecycleRegistry.removeObserver, parameter observer
image

Searching for removeObserver in our entire project returns only this line in react-native-screens:

mViewToLifecycleMap[view]?.removeObserver(view)

Steps to reproduce

We can't seem to reproduce.
It seems to be happening only on Android. Maybe on app start (we don't see any breadcrumbs in Sentry).

Snack or a link to a repository

Couldn't repro in snack.

Screens version

3.18.2

React Native version

0.71.8

Platforms

Android

JavaScript runtime

Hermes

Workflow

React Native (without Expo)

Architecture

Paper (Old Architecture)

Build type

Release mode

Device

Real device

Device model

Redmi Note 9 Pro Max - Android 11

Acknowledgements

Yes

@github-actions github-actions bot added Platform: Android This issue is specific to Android Missing repro This issue need minimum repro scenario labels May 30, 2023
@github-actions
Copy link

Hey! 👋

The issue doesn't seem to contain a minimal reproduction.

Could you provide a snack or a link to a GitHub repository under your username that reproduces the problem?

@sregg
Copy link
Author

sregg commented May 30, 2023

We can't even repro in our own app. It seems to be happening intermittently for some users only.

@AZIMAT
Copy link

AZIMAT commented Jun 6, 2023

I have this issue too,
We can't reproduce it. but some users were affected after updating compile SDK to 33.

@AZIMAT
Copy link

AZIMAT commented Jun 6, 2023

@sregg do you find any solutions?

@sregg
Copy link
Author

sregg commented Jun 6, 2023

I'm gonna do a patch using patch-package today and see if that fixes it.
I'll submit a PR if that helps.

@AZIMAT
Copy link

AZIMAT commented Jun 6, 2023

I'm gonna do a patch using patch-package today and see if that fixes it. I'll submit a PR if that helps.

fun <T> unregister(view: T) where T : View, T : LifecycleObserver? { if(view != null) { mViewToLifecycleMap[view]?.removeObserver(view) } }
I'm going to check this line of code.

@AZIMAT
Copy link

AZIMAT commented Jun 6, 2023

I'm gonna do a patch using patch-package today and see if that fixes it. I'll submit a PR if that helps.

May I have your patch?

@sregg
Copy link
Author

sregg commented Jun 6, 2023

I'm gonna do a patch using patch-package today and see if that fixes it. I'll submit a PR if that helps.

fun <T> unregister(view: T) where T : View, T : LifecycleObserver? { if(view != null) { mViewToLifecycleMap[view]?.removeObserver(view) } }
I'm going to check this line of code.

That was my plan for the patch

@AZIMAT
Copy link

AZIMAT commented Jun 6, 2023

I'm gonna do a patch using patch-package today and see if that fixes it. I'll submit a PR if that helps.

fun <T> unregister(view: T) where T : View, T : LifecycleObserver? { if(view != null) { mViewToLifecycleMap[view]?.removeObserver(view) } }
I'm going to check this line of code.

That was my plan for the patch

Please share your patch result.

@sregg
Copy link
Author

sregg commented Jun 6, 2023

Here's the patch:

diff --git a/node_modules/react-native-screens/android/src/main/java/com/swmansion/rnscreens/LifecycleHelper.kt b/node_modules/react-native-screens/android/src/main/java/com/swmansion/rnscreens/LifecycleHelper.kt
index 41bfc80..5925472 100644
--- a/node_modules/react-native-screens/android/src/main/java/com/swmansion/rnscreens/LifecycleHelper.kt
+++ b/node_modules/react-native-screens/android/src/main/java/com/swmansion/rnscreens/LifecycleHelper.kt
@@ -43,6 +43,9 @@ class LifecycleHelper {
     }
 
     fun <T> unregister(view: T) where T : View, T : LifecycleObserver? {
+        if (view == null) {
+            return
+        }
         mViewToLifecycleMap[view]?.removeObserver(view)
     }

@AZIMAT
Copy link

AZIMAT commented Jun 7, 2023

@sregg I have this issue in sentry again.

@sregg
Copy link
Author

sregg commented Jun 7, 2023

Even after that patch?

@AZIMAT
Copy link

AZIMAT commented Jun 7, 2023

Even after that patch?

Yeap.

@matous94
Copy link

matous94 commented Jun 7, 2023

I have the same problem, but my react-native-screen version (3.20.0) doesn't contain the file you patched anymore or any other removeObserver call. There are removeObserver calls in other dependencies though. Mostly expo libraries in my case. I tried to patch one suspicious file, that does some compatibility stuff between Expo and React Native Screens, but it didn't work.

https://github.com/expo/expo/blob/main/packages/expo-modules-core/android/src/main/java/expo/modules/kotlin/activityresult/AppContextActivityResultRegistry.kt

@AZIMAT
Copy link

AZIMAT commented Jun 7, 2023

@matous94 Can you reproduce this issue on a real device?

@matous94
Copy link

matous94 commented Jun 7, 2023

It actually happens only on real device, in preview/production build, which makes testing quite tedious, since it's not happening in Expo dev-client.

Also I just noticed the "Steps to reproduce" for this issue are different from mine. For me it happens when I call Updates.reloadAsync. I use it to reload app at logout, expired session token etc.

But I think it's quite possible that the underlying issue is the same/similiar.

@AZIMAT
Copy link

AZIMAT commented Jun 7, 2023

@sregg RNScreen 3.2 doesn't contain the file that we patched yesterday.

@sregg
Copy link
Author

sregg commented Jun 7, 2023

Does that mean it's fixed?
I'll try it out

@AZIMAT
Copy link

AZIMAT commented Jun 7, 2023

Does that mean it's fixed? I'll try it out

Nope, I published on production with version 3.2.0 and i have same issues in sentry.

@matous94
Copy link

matous94 commented Jun 8, 2023

I just got the following, more detailed error message in dev in terminal after hot-reloading. I will look into it later, but it seems the error might be coming from sentry package? Possibly the same issue

  androidx.lifecycle.LifecycleRegistry.removeObserver(Unknown Source:3)
  io.sentry.android.core.AppLifecycleIntegration.removeObserver(AppLifecycleIntegration.java:112)
  io.sentry.android.core.AppLifecycleIntegration.lambda$close$1$io-sentry-android-core-AppLifecycleIntegration(AppLifecycleIntegration.java:123)
  io.sentry.android.core.AppLifecycleIntegration$$ExternalSyntheticLambda0.run(Unknown Source:2)
  android.os.Handler.handleCallback(Handler.java:942)
  android.os.Handler.dispatchMessage(Handler.java:99)
  android.os.Looper.loopOnce(Looper.java:201)
  android.os.Looper.loop(Looper.java:288)
  android.app.ActivityThread.main(ActivityThread.java:7898)
  java.lang.reflect.Method.invoke(Native Method)
  com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:548)
  com.android.internal.os.ZygoteInit.main(ZygoteInit.java:936)

@sregg
Copy link
Author

sregg commented Jun 8, 2023

Thanks @matous94
Looks promising: getsentry/sentry-java#2675.
Closing ticket.

@sregg sregg closed this as completed Jun 8, 2023
@DiorAbjalilov
Copy link

I have this issue too, We can't reproduce it. but some users were affected after updating compile SDK to 33.

I also have sdk 33. how can I solve this problem

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Missing repro This issue need minimum repro scenario Platform: Android This issue is specific to Android
Projects
None yet
Development

No branches or pull requests

4 participants