From 0f0c9866cacf29aac408be88894e262e8991890e Mon Sep 17 00:00:00 2001 From: Joshua Gross Date: Tue, 7 Apr 2020 15:21:02 -0700 Subject: [PATCH] Fix crash in FabricUIManager.onMeasure Summary: Changelog: [Internal] The cause of crash was `NullPointerException`, which happened because of `mReactContextForRootTag.get(rootTag)` returning `null`. This is solved by checking whether it returns `null` before passing it to `I18nUtil`. Reviewed By: mdvacca Differential Revision: D20890623 fbshipit-source-id: c884c6838b83b944a5438375a4c060c1f5b1dc6e --- .../react/fabric/FabricUIManager.java | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/ReactAndroid/src/main/java/com/facebook/react/fabric/FabricUIManager.java b/ReactAndroid/src/main/java/com/facebook/react/fabric/FabricUIManager.java index 9554b262ed..5bc9ab4627 100644 --- a/ReactAndroid/src/main/java/com/facebook/react/fabric/FabricUIManager.java +++ b/ReactAndroid/src/main/java/com/facebook/react/fabric/FabricUIManager.java @@ -816,14 +816,29 @@ public class FabricUIManager implements UIManager, LifecycleEventListener { if (ENABLE_FABRIC_LOGS) { FLog.d(TAG, "Updating Root Layout Specs"); } + + ThemedReactContext reactContext = mReactContextForRootTag.get(rootTag); + boolean isRTL = false; + boolean doLeftAndRightSwapInRTL = false; + if (reactContext != null) { + isRTL = I18nUtil.getInstance().isRTL(reactContext); + doLeftAndRightSwapInRTL = I18nUtil.getInstance().doLeftAndRightSwapInRTL(reactContext); + } else { + // TODO T65116569: analyze why this happens + ReactSoftException.logSoftException( + TAG, + new IllegalStateException( + "updateRootLayoutSpecs called before ReactContext set for tag: " + rootTag)); + } + mBinding.setConstraints( rootTag, getMinSize(widthMeasureSpec), getMaxSize(widthMeasureSpec), getMinSize(heightMeasureSpec), getMaxSize(heightMeasureSpec), - I18nUtil.getInstance().isRTL(mReactContextForRootTag.get(rootTag)), - I18nUtil.getInstance().doLeftAndRightSwapInRTL(mReactContextForRootTag.get(rootTag))); + isRTL, + doLeftAndRightSwapInRTL); } public void receiveEvent(int reactTag, String eventName, @Nullable WritableMap params) {