workaround to prevent NPE in ReactViewGroup.dispatchProvideStructure

Summary:
This diff adds a workaround to prevent a NPE to be thrown when the user tap on Android assistant.
The Android stacktrace doesn't help to determine what is the root cause
This is affecting few users in the route: react_MarketplaceProductDetailsFromPostIDRoute

see https://our.intern.facebook.com/intern/logview/details/facebook_android_crashes/b4858cd35bd3496922e5dad4cca70fff/?trace_key=d46b402c3f0cc48c33613b279439a8bf for more details

Reviewed By: fkgozali

Differential Revision: D13586092

fbshipit-source-id: 70f44ab3e32b0c0334e61e8e358c1441944d2727
This commit is contained in:
David Vacca
2019-01-04 18:56:40 -08:00
committed by Facebook Github Bot
parent 9380ec0d23
commit 3d12ad5b1a

View File

@@ -7,6 +7,7 @@
package com.facebook.react.views.view;
import android.annotation.TargetApi;
import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
@@ -19,6 +20,7 @@ import android.os.Build;
import android.view.MotionEvent;
import android.view.View;
import android.view.ViewGroup;
import android.view.ViewStructure;
import android.view.animation.Animation;
import com.facebook.common.logging.FLog;
import com.facebook.infer.annotation.Assertions;
@@ -43,6 +45,8 @@ import com.facebook.react.uimanager.ViewProps;
import com.facebook.yoga.YogaConstants;
import javax.annotation.Nullable;
import static com.facebook.react.common.ReactConstants.TAG;
/**
* Backing for a React View. Has support for borders, but since borders aren't common, lazy
* initializes most of the storage needed for them.
@@ -150,6 +154,16 @@ public class ReactViewGroup extends ViewGroup implements
// `layout` is called on all RN-managed views by `NativeViewHierarchyManager`
}
@TargetApi(23)
@Override
public void dispatchProvideStructure(ViewStructure structure) {
try {
super.dispatchProvideStructure(structure);
} catch (NullPointerException e) {
FLog.e(TAG, "NullPointerException when executing dispatchProvideStructure", e);
}
}
@Override
public void setBackgroundColor(int color) {
if (color == Color.TRANSPARENT && mReactBackgroundDrawable == null) {
@@ -673,7 +687,7 @@ public class ReactViewGroup extends ViewGroup implements
dispatchOverflowDraw(canvas);
super.dispatchDraw(canvas);
} catch (NullPointerException e) {
FLog.e(ReactConstants.TAG, "NullPointerException when executing ViewGroup.dispatchDraw method", e);
FLog.e(TAG, "NullPointerException when executing ViewGroup.dispatchDraw method", e);
} catch (StackOverflowError e) {
// Adding special exception management for StackOverflowError for logging purposes.
// This will be removed in the future.