From be5235f86d6151b633111d3c8bd91a391934792d Mon Sep 17 00:00:00 2001 From: "Andrew Y. Chen" Date: Thu, 16 Feb 2017 13:44:18 -0800 Subject: [PATCH] Fail safely if there are extra DrawView commands in ClippingDrawCommandManager Reviewed By: ahmedre Differential Revision: D4525823 fbshipit-source-id: ebae2fe813f86b33a4ede3d42a9968a05f4bb451 --- .../src/main/java/com/facebook/react/flat/BUCK | 2 +- .../react/flat/ClippingDrawCommandManager.java | 17 ++++++++++++++++- 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/ReactAndroid/src/main/java/com/facebook/react/flat/BUCK b/ReactAndroid/src/main/java/com/facebook/react/flat/BUCK index 1680f79c5..3687f0355 100644 --- a/ReactAndroid/src/main/java/com/facebook/react/flat/BUCK +++ b/ReactAndroid/src/main/java/com/facebook/react/flat/BUCK @@ -5,6 +5,7 @@ android_library( srcs = glob(['*.java']), deps = [ YOGA_TARGET, + react_native_dep('libraries/fbcore/src/main/java/com/facebook/common/logging:logging'), react_native_dep('libraries/fresco/fresco-react-native:fbcore'), react_native_dep('libraries/fresco/fresco-react-native:fresco-drawee'), react_native_dep('libraries/fresco/fresco-react-native:fresco-react-native'), @@ -32,4 +33,3 @@ android_library( 'PUBLIC', ], ) - diff --git a/ReactAndroid/src/main/java/com/facebook/react/flat/ClippingDrawCommandManager.java b/ReactAndroid/src/main/java/com/facebook/react/flat/ClippingDrawCommandManager.java index 979166bd5..0008ee69e 100644 --- a/ReactAndroid/src/main/java/com/facebook/react/flat/ClippingDrawCommandManager.java +++ b/ReactAndroid/src/main/java/com/facebook/react/flat/ClippingDrawCommandManager.java @@ -12,6 +12,7 @@ package com.facebook.react.flat; import javax.annotation.Nullable; import java.util.ArrayList; +import java.util.Arrays; import android.graphics.Canvas; import android.graphics.Rect; @@ -20,6 +21,7 @@ import android.util.SparseIntArray; import android.view.View; import android.view.animation.Animation; +import com.facebook.common.logging.FLog; import com.facebook.infer.annotation.Assertions; import com.facebook.react.uimanager.ReactClippingViewGroup; import com.facebook.react.uimanager.ReactClippingViewGroupHelper; @@ -144,6 +146,9 @@ import com.facebook.react.uimanager.ReactClippingViewGroupHelper; * loosely sorted as well when clipping. */ /* package */ abstract class ClippingDrawCommandManager extends DrawCommandManager { + + private static final String TAG = ClippingDrawCommandManager.class.getSimpleName(); + private final FlatViewGroup mFlatViewGroup; private DrawCommand[] mDrawCommands = DrawCommand.EMPTY_ARRAY; protected float[] mCommandMaxBottom = StateBuilder.EMPTY_FLOAT_ARRAY; @@ -616,7 +621,17 @@ import com.facebook.react.uimanager.ReactClippingViewGroupHelper; // If we get here, it means we have drawn all the views, now just draw the remaining draw // commands. while (commandIndex < mStop) { - mDrawCommands[commandIndex++].draw(mFlatViewGroup, canvas); + DrawCommand command = mDrawCommands[commandIndex++]; + if (command instanceof DrawView) { + // We should never have more DrawView commands at this point. But in case we do, fail safely + // by ignoring the DrawView command + FLog.w( + TAG, + "Unexpected DrawView command at index " + (commandIndex-1) + " with mStop=" + + mStop + ". " + Arrays.toString(mDrawCommands)); + continue; + } + command.draw(mFlatViewGroup, canvas); } }