Skip to content

Commit

Permalink
RN crash when processing Exception with null message
Browse files Browse the repository at this point in the history
Summary: This diff fixes a crash that happens when a component throws an exception that contains a null message

Reviewed By: achen1

Differential Revision: D10429661

fbshipit-source-id: 9faed36906844b51f5a3dc2b3cbc80ede6b93457
  • Loading branch information
mdvacca authored and facebook-github-bot committed Oct 22, 2018
1 parent b51a1d5 commit 6debfdf
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 7 deletions.
3 changes: 3 additions & 0 deletions ReactAndroid/src/main/java/com/facebook/react/devsupport/BUCK
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ rn_android_library(
name = "devsupport",
srcs = glob(["*.java"]),
manifest = "AndroidManifest.xml",
provided_deps = [
react_native_dep("third-party/android/support/v4:lib-support-v4"),
],
visibility = [
"PUBLIC",
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import android.hardware.SensorManager;
import android.net.Uri;
import android.os.AsyncTask;
import android.support.annotation.Nullable;
import android.util.Pair;
import android.widget.Toast;
import com.facebook.common.logging.FLog;
Expand All @@ -31,7 +32,6 @@
import com.facebook.react.bridge.CatalystInstance;
import com.facebook.react.bridge.DefaultNativeModuleCallExceptionHandler;
import com.facebook.react.bridge.JavaJSExecutor;
import com.facebook.react.bridge.JavaScriptContextHolder;
import com.facebook.react.bridge.NativeDeltaClient;
import com.facebook.react.bridge.ReactContext;
import com.facebook.react.bridge.ReactMarker;
Expand Down Expand Up @@ -64,7 +64,6 @@
import java.util.concurrent.ExecutionException;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;
import javax.annotation.Nullable;
import okhttp3.MediaType;
import okhttp3.OkHttpClient;
import okhttp3.Request;
Expand Down Expand Up @@ -295,7 +294,7 @@ private class JSExceptionLogger implements ExceptionLogger {

@Override
public void log(Exception e) {
StringBuilder message = new StringBuilder(e.getMessage());
StringBuilder message = new StringBuilder(e.getMessage() == null ? "Exception in native call from JS" : e.getMessage());
Throwable cause = e.getCause();
while (cause != null) {
message.append("\n\n").append(cause.getMessage());
Expand All @@ -320,7 +319,7 @@ public void log(Exception e) {
}

@Override
public void showNewJavaError(String message, Throwable e) {
public void showNewJavaError(@Nullable String message, Throwable e) {
FLog.e(ReactConstants.TAG, "Exception in native call", e);
showNewError(message, StackTraceHelper.convertJavaStackTrace(e), JAVA_ERROR_COOKIE, ErrorType.NATIVE);
}
Expand Down Expand Up @@ -414,7 +413,7 @@ private void hideDevOptionsDialog() {
}

private void showNewError(
final String message,
@Nullable final String message,
final StackFrame[] stack,
final int errorCookie,
final ErrorType errorType) {
Expand Down Expand Up @@ -893,7 +892,7 @@ private void handlePokeSamplingProfiler() {
}

private void updateLastErrorInfo(
final String message,
@Nullable final String message,
final StackFrame[] stack,
final int errorCookie,
final ErrorType errorType) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
package com.facebook.react.devsupport;

import android.content.Context;
import android.support.annotation.Nullable;
import android.text.SpannedString;

import com.facebook.react.devsupport.interfaces.StackFrame;
Expand Down Expand Up @@ -42,7 +43,7 @@ interface ReportCompletedListener {
/**
* Handle the information from the redbox.
*/
void handleRedbox(String title, StackFrame[] stack, ErrorType errorType);
void handleRedbox(@Nullable String title, StackFrame[] stack, ErrorType errorType);

/**
* Whether the report feature is enabled.
Expand Down

1 comment on commit 6debfdf

@gengjiawen
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like broken current ci @mdvacca

Please sign in to comment.