Skip to content

Commit 311cef3

Browse files
GijsWeteringsfacebook-github-bot
authored andcommitted
Fix Nullsafe FIXMEs for DevServerHelper.java and mark nullsafe (facebook#50060)
Summary: Pull Request resolved: facebook#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
1 parent e9af9a1 commit 311cef3

File tree

1 file changed

+9
-6
lines changed

1 file changed

+9
-6
lines changed

packages/react-native/ReactAndroid/src/main/java/com/facebook/react/devsupport/DevServerHelper.java

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
import androidx.annotation.Nullable;
1616
import com.facebook.common.logging.FLog;
1717
import com.facebook.infer.annotation.Assertions;
18+
import com.facebook.infer.annotation.Nullsafe;
1819
import com.facebook.react.bridge.ReactContext;
1920
import com.facebook.react.common.ReactConstants;
2021
import com.facebook.react.devsupport.interfaces.DevBundleDownloadListener;
@@ -59,6 +60,7 @@
5960
* <li>Genymotion emulator with default settings: 10.0.3.2
6061
* </ul>
6162
*/
63+
@Nullsafe(Nullsafe.Mode.LOCAL)
6264
public class DevServerHelper {
6365
private static final int HTTP_CONNECT_TIMEOUT_MS = 5000;
6466

@@ -205,11 +207,13 @@ public void openInspectorConnection() {
205207
protected Void doInBackground(Void... params) {
206208
Map<String, String> metadata =
207209
AndroidInfoHelpers.getInspectorHostMetadata(mApplicationContext);
208-
210+
String deviceName = metadata.get("deviceName");
211+
if (deviceName == null) {
212+
FLog.w(ReactConstants.TAG, "Could not get device name from Inspector Host Metadata.");
213+
return null;
214+
}
209215
mInspectorPackagerConnection =
210-
new CxxInspectorPackagerConnection(
211-
// NULLSAFE_FIXME[Parameter Not Nullable]
212-
getInspectorDeviceUrl(), metadata.get("deviceName"), mPackageName);
216+
new CxxInspectorPackagerConnection(getInspectorDeviceUrl(), deviceName, mPackageName);
213217
mInspectorPackagerConnection.connect();
214218
return null;
215219
}
@@ -453,12 +457,11 @@ public String getSourceUrl(String mainModuleName) {
453457
final Request request = new Request.Builder().url(resourceURL).build();
454458

455459
try (Response response = mClient.newCall(request).execute()) {
456-
if (!response.isSuccessful()) {
460+
if (!response.isSuccessful() || response.body() == null) {
457461
return null;
458462
}
459463

460464
try (Sink output = Okio.sink(outputFile)) {
461-
// NULLSAFE_FIXME[Nullable Dereference]
462465
Okio.buffer(response.body().source()).readAll(output);
463466
}
464467

0 commit comments

Comments
 (0)