From 311cef3c0df8f112e4bfae4663ba9dd04e465d5e Mon Sep 17 00:00:00 2001 From: Gijs Weterings Date: Tue, 18 Mar 2025 06:08:17 -0700 Subject: [PATCH] Fix Nullsafe FIXMEs for DevServerHelper.java and mark nullsafe (#50060) Summary: Pull Request resolved: https://github.com/facebook/react-native/pull/50060 Gone trough all the FIXMEs added in the previous diff by the nullsafe tool, marked the class as nullsafe and ensured no remaining violations. Changelog: [Android][Fixed] Made DevServerHelper.java nullsafe Reviewed By: rshest Differential Revision: D71126391 fbshipit-source-id: 0d39b23d0d96f32f25ac1003d849428000777852 --- .../react/devsupport/DevServerHelper.java | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/devsupport/DevServerHelper.java b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/devsupport/DevServerHelper.java index 8350285e766..5411029777a 100644 --- a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/devsupport/DevServerHelper.java +++ b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/devsupport/DevServerHelper.java @@ -15,6 +15,7 @@ import androidx.annotation.NonNull; import androidx.annotation.Nullable; import com.facebook.common.logging.FLog; import com.facebook.infer.annotation.Assertions; +import com.facebook.infer.annotation.Nullsafe; import com.facebook.react.bridge.ReactContext; import com.facebook.react.common.ReactConstants; import com.facebook.react.devsupport.interfaces.DevBundleDownloadListener; @@ -59,6 +60,7 @@ import okio.Sink; *
  • Genymotion emulator with default settings: 10.0.3.2 * */ +@Nullsafe(Nullsafe.Mode.LOCAL) public class DevServerHelper { private static final int HTTP_CONNECT_TIMEOUT_MS = 5000; @@ -205,11 +207,13 @@ public class DevServerHelper { protected Void doInBackground(Void... params) { Map metadata = AndroidInfoHelpers.getInspectorHostMetadata(mApplicationContext); - + String deviceName = metadata.get("deviceName"); + if (deviceName == null) { + FLog.w(ReactConstants.TAG, "Could not get device name from Inspector Host Metadata."); + return null; + } mInspectorPackagerConnection = - new CxxInspectorPackagerConnection( - // NULLSAFE_FIXME[Parameter Not Nullable] - getInspectorDeviceUrl(), metadata.get("deviceName"), mPackageName); + new CxxInspectorPackagerConnection(getInspectorDeviceUrl(), deviceName, mPackageName); mInspectorPackagerConnection.connect(); return null; } @@ -453,12 +457,11 @@ public class DevServerHelper { final Request request = new Request.Builder().url(resourceURL).build(); try (Response response = mClient.newCall(request).execute()) { - if (!response.isSuccessful()) { + if (!response.isSuccessful() || response.body() == null) { return null; } try (Sink output = Okio.sink(outputFile)) { - // NULLSAFE_FIXME[Nullable Dereference] Okio.buffer(response.body().source()).readAll(output); }