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

Crash: Attempt to invoke interface method 'void com.facebook.react.bridge.Promise.resolve(java.lang.Object)' on a null object reference #453

Open
dgrover-spotnana opened this issue Apr 11, 2024 · 4 comments

Comments

@dgrover-spotnana
Copy link

dgrover-spotnana commented Apr 11, 2024

Which platform(s) does your issue occur on?

Android Device (OS Level 34)

Please, provide the following version numbers that your issue occurs with:

"react-native": "0.70.8",
"react-native-inappbrowser-reborn": "^3.7.0"

Please, explain the issue in as much detail as possible.

The issue was reported on our Instabug for one of the users. Although this is the first occurrence, it'll be great if we could get some insights around this crash early on.

java.lang.NullPointerException: Attempt to invoke interface method 'void com.facebook.react.bridge.Promise.resolve(java.lang.Object)' on a null object reference
	 at com.proyecto26.inappbrowser.RNInAppBrowser.close(RNInAppBrowser.java:241)
	 at com.proyecto26.inappbrowser.RNInAppBrowserModule.close(RNInAppBrowserModule.java:37)
	 at java.lang.reflect.Method.invoke(Native Method)
	 at com.facebook.react.bridge.JavaMethodWrapper.invoke(JavaMethodWrapper.java:372)
	 at com.facebook.react.bridge.JavaModuleWrapper.invoke(JavaModuleWrapper.java:188)
	 at com.facebook.jni.NativeRunnable.run(Native Method)
	 at android.os.Handler.handleCallback(Handler.java:958)
	 at android.os.Handler.dispatchMessage(Handler.java:99)
	 at com.facebook.react.bridge.queue.MessageQueueThreadHandler.dispatchMessage(MessageQueueThreadHandler.java:27)
	 at android.os.Looper.loopOnce(Looper.java:230)
	 at android.os.Looper.loop(Looper.java:319)
	 at com.facebook.react.bridge.queue.MessageQueueThreadImpl$4.run(MessageQueueThreadImpl.java:228)
	 at java.lang.Thread.run(Thread.java:1012)
@MichaelPlan
Copy link

Same crash for many users

@akarshkumar
Copy link

Any update on this issue?

@ingvardm
Copy link

ingvardm commented Aug 12, 2024

Happens for some users here as well. react_native 0.74.3 and react-native-inappbrowser-reborn is 3.7.0
happens on Samsung Galaxy S22 - Android 14.0.0 and Pixel 7 - Android 14.0.0

Version 3.6.3 works

@MAKARD
Copy link

MAKARD commented Sep 18, 2024

this patch helped us to mitigate the crash

diff --git a/node_modules/react-native-inappbrowser-reborn/android/src/main/java/com/proyecto26/inappbrowser/ChromeTabsManagerActivity.java b/node_modules/react-native-inappbrowser-reborn/android/src/main/java/com/proyecto26/inappbrowser/ChromeTabsManagerActivity.java
index 78bb33a..7bf95f1 100644
--- a/node_modules/react-native-inappbrowser-reborn/android/src/main/java/com/proyecto26/inappbrowser/ChromeTabsManagerActivity.java
+++ b/node_modules/react-native-inappbrowser-reborn/android/src/main/java/com/proyecto26/inappbrowser/ChromeTabsManagerActivity.java
@@ -58,7 +58,10 @@ public class ChromeTabsManagerActivity extends Activity {
       }
     } catch (Exception e) {
       isError = true;
-      EventBus.getDefault().post(new ChromeTabsDismissedEvent("Unable to open url.", resultType, isError));
+
+      String errorMessage = e.getMessage();
+
+      EventBus.getDefault().post(new ChromeTabsDismissedEvent((errorMessage != null) ? errorMessage : "Unable to open url.", resultType, isError));
       finish();
       e.printStackTrace();
     }
diff --git a/node_modules/react-native-inappbrowser-reborn/android/src/main/java/com/proyecto26/inappbrowser/RNInAppBrowser.java b/node_modules/react-native-inappbrowser-reborn/android/src/main/java/com/proyecto26/inappbrowser/RNInAppBrowser.java
index 28158ce..58889cf 100644
--- a/node_modules/react-native-inappbrowser-reborn/android/src/main/java/com/proyecto26/inappbrowser/RNInAppBrowser.java
+++ b/node_modules/react-native-inappbrowser-reborn/android/src/main/java/com/proyecto26/inappbrowser/RNInAppBrowser.java
@@ -224,23 +224,19 @@ public class RNInAppBrowser {
   }
 
   public void close() {
-    if (mOpenBrowserPromise == null) {
-      return;
-    }
-
+    /*
+      Reducing the number of places where promise is resolving mitigates risks of race conditions.
+      
+    */
     if (currentActivity == null) {
-      mOpenBrowserPromise.reject(ERROR_CODE, "No activity");
-      mOpenBrowserPromise = null;
+      EventBus.getDefault().post(new ChromeTabsDismissedEvent("No activity", "", true));
       return;
     }
 
-    unRegisterEventBus();
-
-    WritableMap result = Arguments.createMap();
-    result.putString("type", "dismiss");
-    mOpenBrowserPromise.resolve(result);
-    mOpenBrowserPromise = null;
-
+    /*
+      Do not resolve promise directly here, but instead send dismiss intent,
+      which subsequently resolves promise within onEvent listener.
+    */
     currentActivity.startActivity(
         ChromeTabsManagerActivity.createDismissIntent(currentActivity));
   }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants