From 4c8ea858a53a68af688c5a5755f4104c674fee0e Mon Sep 17 00:00:00 2001 From: Gijs Weterings Date: Wed, 9 Apr 2025 09:07:30 -0700 Subject: [PATCH] fix nullsafe FIXMEs for PromiseImpl.java and mark nullsafe Summary: 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 PromiseImpl.java nullsafe Reviewed By: alanleedev Differential Revision: D72384070 fbshipit-source-id: 142a0e001af42ebb8cc1c8301b3ec7f586191d92 --- .../facebook/react/bridge/PromiseImpl.java | 23 ++++++++----------- 1 file changed, 9 insertions(+), 14 deletions(-) diff --git a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/bridge/PromiseImpl.java b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/bridge/PromiseImpl.java index 17be00be2db..97340676fd2 100644 --- a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/bridge/PromiseImpl.java +++ b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/bridge/PromiseImpl.java @@ -7,8 +7,8 @@ package com.facebook.react.bridge; -import androidx.annotation.NonNull; import androidx.annotation.Nullable; +import com.facebook.infer.annotation.Nullsafe; import com.facebook.proguard.annotations.DoNotStrip; /* @@ -18,6 +18,7 @@ import com.facebook.proguard.annotations.DoNotStrip; * Methods annotated with {@link ReactMethod} that use a {@link Promise} as the last parameter * will be marked as "promise" and will return a promise when invoked from JavaScript. */ +@Nullsafe(Nullsafe.Mode.LOCAL) @DoNotStrip public class PromiseImpl implements Promise { // Number of stack frames to parse and return to mReject.invoke @@ -55,8 +56,7 @@ public class PromiseImpl implements Promise { * @param value Object */ @Override - // NULLSAFE_FIXME[Inconsistent Subclass Parameter Annotation] - public void resolve(Object value) { + public void resolve(@Nullable Object value) { if (mResolve != null) { mResolve.invoke(value); mResolve = null; @@ -71,8 +71,7 @@ public class PromiseImpl implements Promise { * @param message String */ @Override - // NULLSAFE_FIXME[Inconsistent Subclass Parameter Annotation] - public void reject(String code, String message) { + public void reject(String code, @Nullable String message) { reject(code, message, /*Throwable*/ null, /*WritableMap*/ null); } @@ -83,8 +82,7 @@ public class PromiseImpl implements Promise { * @param throwable Throwable */ @Override - // NULLSAFE_FIXME[Inconsistent Subclass Parameter Annotation] - public void reject(String code, Throwable throwable) { + public void reject(String code, @Nullable Throwable throwable) { reject(code, /*Message*/ null, throwable, /*WritableMap*/ null); } @@ -96,8 +94,7 @@ public class PromiseImpl implements Promise { * @param throwable Throwable */ @Override - // NULLSAFE_FIXME[Inconsistent Subclass Parameter Annotation] - public void reject(String code, String message, Throwable throwable) { + public void reject(String code, @Nullable String message, @Nullable Throwable throwable) { reject(code, message, throwable, /*WritableMap*/ null); } @@ -135,7 +132,7 @@ public class PromiseImpl implements Promise { * @param userInfo WritableMap */ @Override - public void reject(String code, @NonNull WritableMap userInfo) { + public void reject(String code, WritableMap userInfo) { reject(code, /*Message*/ null, /*Throwable*/ null, userInfo); } @@ -147,8 +144,7 @@ public class PromiseImpl implements Promise { * @param userInfo WritableMap */ @Override - // NULLSAFE_FIXME[Inconsistent Subclass Parameter Annotation] - public void reject(String code, Throwable throwable, WritableMap userInfo) { + public void reject(String code, @Nullable Throwable throwable, WritableMap userInfo) { reject(code, /*Message*/ null, throwable, userInfo); } @@ -161,8 +157,7 @@ public class PromiseImpl implements Promise { * @param userInfo WritableMap */ @Override - // NULLSAFE_FIXME[Inconsistent Subclass Parameter Annotation] - public void reject(String code, String message, @NonNull WritableMap userInfo) { + public void reject(String code, @Nullable String message, WritableMap userInfo) { reject(code, message, /*Throwable*/ null, userInfo); }