From 114c9a2953b70b7abf9f2c7c6297e3b45dc9e309 Mon Sep 17 00:00:00 2001
From: Thomas Nardone <tnardone@fb.com>
Date: Fri, 10 Jan 2025 13:41:09 -0800
Subject: [PATCH] Mark nullsafe fixmes in views/text/frescosupport

Differential Revision: D67992721
---
 .../FrescoBasedReactTextInlineImageShadowNode.java       | 5 +++++
 .../FrescoBasedReactTextInlineImageSpan.java             | 9 +++++++++
 2 files changed, 14 insertions(+)

diff --git a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/views/text/frescosupport/FrescoBasedReactTextInlineImageShadowNode.java b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/views/text/frescosupport/FrescoBasedReactTextInlineImageShadowNode.java
index a512b20833caca..0c87fa495e05e7 100644
--- a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/views/text/frescosupport/FrescoBasedReactTextInlineImageShadowNode.java
+++ b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/views/text/frescosupport/FrescoBasedReactTextInlineImageShadowNode.java
@@ -14,6 +14,7 @@
 import com.facebook.common.logging.FLog;
 import com.facebook.common.util.UriUtil;
 import com.facebook.drawee.controller.AbstractDraweeControllerBuilder;
+import com.facebook.infer.annotation.Nullsafe;
 import com.facebook.react.bridge.Dynamic;
 import com.facebook.react.bridge.ReadableArray;
 import com.facebook.react.bridge.ReadableMap;
@@ -27,9 +28,11 @@
 import java.util.Locale;
 
 /** Shadow node that represents an inline image. Loading is done using Fresco. */
+@Nullsafe(Nullsafe.Mode.LOCAL)
 class FrescoBasedReactTextInlineImageShadowNode extends ReactTextInlineImageShadowNode {
 
   private @Nullable Uri mUri;
+  // NULLSAFE_FIXME[Field Not Initialized]
   private ReadableMap mHeaders;
   private final AbstractDraweeControllerBuilder mDraweeControllerBuilder;
   private final @Nullable Object mCallerContext;
@@ -47,6 +50,7 @@ public FrescoBasedReactTextInlineImageShadowNode(
   @ReactProp(name = "src")
   public void setSource(@Nullable ReadableArray sources) {
     final String source =
+        // NULLSAFE_FIXME[Nullable Dereference]
         (sources == null || sources.size() == 0) ? null : sources.getMap(0).getString("uri");
     Uri uri = null;
     if (source != null) {
@@ -145,6 +149,7 @@ public TextInlineImageSpan buildInlineImageSpan() {
         getHeaders(),
         getDraweeControllerBuilder(),
         getCallerContext(),
+        // NULLSAFE_FIXME[Parameter Not Nullable]
         mResizeMode);
   }
 
diff --git a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/views/text/frescosupport/FrescoBasedReactTextInlineImageSpan.java b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/views/text/frescosupport/FrescoBasedReactTextInlineImageSpan.java
index 2f3cf1cc3daa82..2bc55a1a0daf67 100644
--- a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/views/text/frescosupport/FrescoBasedReactTextInlineImageSpan.java
+++ b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/views/text/frescosupport/FrescoBasedReactTextInlineImageSpan.java
@@ -23,6 +23,7 @@
 import com.facebook.drawee.view.DraweeHolder;
 import com.facebook.imagepipeline.request.ImageRequest;
 import com.facebook.imagepipeline.request.ImageRequestBuilder;
+import com.facebook.infer.annotation.Nullsafe;
 import com.facebook.react.bridge.ReadableMap;
 import com.facebook.react.modules.fresco.ReactNetworkImageRequest;
 import com.facebook.react.uimanager.PixelUtil;
@@ -40,6 +41,7 @@
  * <p>Note: It borrows code from DynamicDrawableSpan and if that code updates how it computes size
  * or draws, we need to update this as well.
  */
+@Nullsafe(Nullsafe.Mode.LOCAL)
 class FrescoBasedReactTextInlineImageSpan extends TextInlineImageSpan {
 
   private @Nullable Drawable mDrawable;
@@ -116,6 +118,7 @@ public int getSize(Paint paint, CharSequence text, int start, int end, Paint.Fon
     return mWidth;
   }
 
+  // NULLSAFE_FIXME[Inconsistent Subclass Parameter Annotation]
   public void setTextView(TextView textView) {
     mTextView = textView;
   }
@@ -140,6 +143,7 @@ public void draw(
           mDraweeControllerBuilder
               .reset()
               .setOldController(mDraweeHolder.getController())
+              // NULLSAFE_FIXME[Parameter Not Nullable]
               .setCallerContext(mCallerContext)
               .setImageRequest(imageRequest)
               .build();
@@ -147,10 +151,13 @@ public void draw(
       mDraweeControllerBuilder.reset();
 
       mDrawable = mDraweeHolder.getTopLevelDrawable();
+      // NULLSAFE_FIXME[Nullable Dereference]
       mDrawable.setBounds(0, 0, mWidth, mHeight);
       if (mTintColor != 0) {
+        // NULLSAFE_FIXME[Nullable Dereference]
         mDrawable.setColorFilter(mTintColor, PorterDuff.Mode.SRC_IN);
       }
+      // NULLSAFE_FIXME[Nullable Dereference]
       mDrawable.setCallback(mTextView);
     }
 
@@ -161,9 +168,11 @@ public void draw(
     // Align to center
     int fontHeight = (int) (paint.descent() - paint.ascent());
     int centerY = y + (int) paint.descent() - fontHeight / 2;
+    // NULLSAFE_FIXME[Nullable Dereference]
     int transY = centerY - (mDrawable.getBounds().bottom - mDrawable.getBounds().top) / 2;
 
     canvas.translate(x, transY);
+    // NULLSAFE_FIXME[Nullable Dereference]
     mDrawable.draw(canvas);
     canvas.restore();
   }