kadiraydinli / react-native-system-navigation-bar

React Native lets you customize the navigation bar for Android.
https://www.npmjs.com/package/react-native-system-navigation-bar
MIT License
270 stars 19 forks source link

Bug: setSystemUIFlags is calling promise.resolve and promise.reject which could cause a NullPointerException #40

Closed roelwuytens closed 1 year ago

roelwuytens commented 1 year ago

We've noticed the following crash with the SystemNavigationBar.:

Fatal Exception: java.lang.NullPointerException: Attempt to invoke interface method 'void com.facebook.react.bridge.Callback.invoke(java.lang.Object[])' on a null object reference
       at com.facebook.react.bridge.PromiseImpl.reject(PromiseImpl.java:231)
       at com.facebook.react.bridge.PromiseImpl.reject(PromiseImpl.java:70)
       at com.reactnativesystemnavigationbar.SystemNavigationBarModule.lambda$setSystemUIFlags$3$com-reactnativesystemnavigationbar-SystemNavigationBarModule(SystemNavigationBarModule.java:265)
       at com.reactnativesystemnavigationbar.SystemNavigationBarModule$$ExternalSyntheticLambda1.run(:6)   

It seems like inside https://github.com/kadiraydinli/react-native-system-navigation-bar/blob/master/android/src/main/java/com/reactnativesystemnavigationbar/SystemNavigationBarModule.java#L254 a Promise.resolve(true) is always called but also a promise.reject("Error: ", "current activity is null"); is possible.

Internally react-native will reset the reject/resolve callback, https://github.com/facebook/react-native/blob/main/ReactAndroid/src/main/java/com/facebook/react/bridge/PromiseImpl.java#L54 So we assume a race condition could cause this issue while inside the reject-function. (At the start the reject-function will check for null, https://github.com/facebook/react-native/blob/main/ReactAndroid/src/main/java/com/facebook/react/bridge/PromiseImpl.java#L173)

We will create a pull request with a fix.

Kind regards, Roel