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
This commit is contained in:
Nick Gerleman
2024-05-30 17:33:43 -07:00
committed by Facebook GitHub Bot
parent e880ed76fe
commit c2c9b27ff2
@@ -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<ReactTextView, ReactTextShadowNode>
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() : "<empty>");
throw e;
}
int textBreakStrategy =
TextAttributeProps.getTextBreakStrategy(