Skip to content

Commit 9527ab1

Browse files
ryancatfacebook-github-bot
authored andcommitted
Add null check for context in redbox surface delegate
Summary: The context could be null or is finishing when we create the redbox surface content view. This diff adds the null check and delegate the message in log when context is not available. Changelog: [Android][Fixed] - Adding null check for context in redbox surface delegate Differential Revision: D34930595 fbshipit-source-id: 91508ded7821033abcd893f70bcfe3cc9ee5b5c2
1 parent 8200f91 commit 9527ab1

File tree

2 files changed

+12
-2
lines changed

2 files changed

+12
-2
lines changed

ReactAndroid/src/main/java/com/facebook/react/devsupport/DevSupportManagerBase.java

+3-2
Original file line numberDiff line numberDiff line change
@@ -343,6 +343,9 @@ private void showNewError(
343343
new Runnable() {
344344
@Override
345345
public void run() {
346+
// Keep a copy of the latest error to be shown by the RedBoxSurface
347+
updateLastErrorInfo(message, stack, errorCookie, errorType);
348+
346349
if (mRedBoxSurfaceDelegate == null) {
347350
@Nullable SurfaceDelegate redBoxSurfaceDelegate = createSurfaceDelegate("RedBox");
348351
if (redBoxSurfaceDelegate != null) {
@@ -361,8 +364,6 @@ public void run() {
361364
return;
362365
}
363366

364-
// The RedBox surface delegate will always show the latest error
365-
updateLastErrorInfo(message, stack, errorCookie, errorType);
366367
mRedBoxSurfaceDelegate.show();
367368
}
368369
});

ReactAndroid/src/main/java/com/facebook/react/devsupport/RedBoxDialogSurfaceDelegate.java

+9
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,15 @@ public void createContentView(String appKey) {
4242
// used here.
4343
RedBoxHandler redBoxHandler = mDevSupportManager.getRedBoxHandler();
4444
Activity context = mDevSupportManager.getCurrentActivity();
45+
if (context == null || context.isFinishing()) {
46+
@Nullable String message = mDevSupportManager.getLastErrorTitle();
47+
FLog.e(
48+
ReactConstants.TAG,
49+
"Unable to launch redbox because react activity "
50+
+ "is not available, here is the error that redbox would've displayed: "
51+
+ (message != null ? message : "N/A"));
52+
return;
53+
}
4554
// Create a new RedBox when currentActivity get updated
4655
mRedBoxContentView = new RedBoxContentView(context);
4756
mRedBoxContentView

0 commit comments

Comments
 (0)