From 3d12ad5b1ac94787f3e4fa8b37273f3b93cb0575 Mon Sep 17 00:00:00 2001 From: David Vacca Date: Fri, 4 Jan 2019 18:56:40 -0800 Subject: [PATCH] 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 --- .../react/views/view/ReactViewGroup.java | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/ReactAndroid/src/main/java/com/facebook/react/views/view/ReactViewGroup.java b/ReactAndroid/src/main/java/com/facebook/react/views/view/ReactViewGroup.java index 5e96198a4a6110..d06f1b0395edd7 100644 --- a/ReactAndroid/src/main/java/com/facebook/react/views/view/ReactViewGroup.java +++ b/ReactAndroid/src/main/java/com/facebook/react/views/view/ReactViewGroup.java @@ -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.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.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 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) { @@ -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.