Skip to content

Commit

Permalink
workaround to prevent NPE in ReactViewGroup.dispatchProvideStructure
Browse files Browse the repository at this point in the history
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
  • Loading branch information
mdvacca authored and facebook-github-bot committed Jan 5, 2019
1 parent 9380ec0 commit 3d12ad5
Showing 1 changed file with 15 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -19,6 +20,7 @@
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;
Expand All @@ -43,6 +45,8 @@
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.
Expand Down Expand Up @@ -150,6 +154,16 @@ public void requestLayout() {
// `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) {
Expand Down Expand Up @@ -673,7 +687,7 @@ protected void dispatchDraw(Canvas canvas) {
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.
Expand Down

0 comments on commit 3d12ad5

Please sign in to comment.