From c2c9b27ff2a7d1bdace8e65d8c889770cb8fd48d Mon Sep 17 00:00:00 2001 From: Nick Gerleman Date: Thu, 30 May 2024 17:33:43 -0700 Subject: [PATCH] Add extra logging for invalid Paragraph Attributes MapBuffer (#44709) Summary: Pull Request resolved: https://github.com/facebook/react-native/pull/44709 Add some extra logging to try to figure out heisenbug, where we cannot find MapBuffer key that we should expect to be present, only during view preallocation. ReadableMapBuffer toString() will itself iterate through MapBuffer entries, so this might not return something sane if underlying MapBuffer is corrupt or wrongly oriented, but should give us more context. We also need to be careful here, to avoid logging the actual state mapbuffer or its binary which may contain text content. Only the paragraph attributes. Changelog: [Internal] Reviewed By: cortinico Differential Revision: D57925730 fbshipit-source-id: cecca1a1fe53b4b417d520e65c30d47243cb2fb2 --- .../react/views/text/ReactTextViewManager.java | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/views/text/ReactTextViewManager.java b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/views/text/ReactTextViewManager.java index 22670ab0517..fe4bc770ff8 100644 --- a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/views/text/ReactTextViewManager.java +++ b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/views/text/ReactTextViewManager.java @@ -12,6 +12,7 @@ import android.os.Build; import android.text.Spannable; import androidx.annotation.NonNull; import androidx.annotation.Nullable; +import com.facebook.common.logging.FLog; import com.facebook.react.R; import com.facebook.react.common.MapBuilder; import com.facebook.react.common.annotations.VisibleForTesting; @@ -37,6 +38,8 @@ public class ReactTextViewManager extends ReactTextAnchorViewManager implements IViewManagerWithChildren { + private static final String TAG = "ReactTextViewManager"; + private static final short TX_STATE_KEY_ATTRIBUTED_STRING = 0; private static final short TX_STATE_KEY_PARAGRAPH_ATTRIBUTES = 1; // used for text input @@ -149,9 +152,18 @@ public class ReactTextViewManager view.getContext(), attributedString, mReactTextViewManagerCallback); view.setSpanned(spanned); - float minimumFontSize = - (float) paragraphAttributes.getDouble(TextLayoutManager.PA_KEY_MINIMUM_FONT_SIZE); - view.setMinimumFontSize(minimumFontSize); + try { + float minimumFontSize = + (float) paragraphAttributes.getDouble(TextLayoutManager.PA_KEY_MINIMUM_FONT_SIZE); + view.setMinimumFontSize(minimumFontSize); + } catch (IllegalArgumentException e) { + // T190482857: We see rare crash with MapBuffer without PA_KEY_MINIMUM_FONT_SIZE entry + FLog.e( + TAG, + "Paragraph Attributes: %s", + paragraphAttributes != null ? paragraphAttributes.toString() : ""); + throw e; + } int textBreakStrategy = TextAttributeProps.getTextBreakStrategy(