fix nullsafe FIXMEs for DynamicFromArray.java and mark nullsafe

Summary:
D65596278 marked the non-primitive return types from ReadableArray as optional, so we have to follow suit

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 DynamicFromArray.java nullsafe

Reviewed By: alanleedev

Differential Revision: D72384069

fbshipit-source-id: c67dc5bfb540af9190f740d565e5bda63d1caaa8
This commit is contained in:
Gijs Weterings
2025-04-09 09:07:30 -07:00
committed by Facebook GitHub Bot
parent 6e5eef9158
commit 3665046c14
5 changed files with 12 additions and 11 deletions
@@ -16,7 +16,7 @@ public interface Dynamic {
public val isNull: Boolean
public fun asArray(): ReadableArray
public fun asArray(): ReadableArray?
public fun asBoolean(): Boolean
@@ -24,9 +24,9 @@ public interface Dynamic {
public fun asInt(): Int
public fun asMap(): ReadableMap
public fun asMap(): ReadableMap?
public fun asString(): String
public fun asString(): String?
public fun recycle(): Unit
}
@@ -70,29 +70,26 @@ class DynamicFromArray implements Dynamic {
}
@Override
public String asString() {
public @Nullable String asString() {
if (mArray == null) {
throw new IllegalStateException("This dynamic value has been recycled");
}
// NULLSAFE_FIXME[Return Not Nullable]
return mArray.getString(mIndex);
}
@Override
public ReadableArray asArray() {
public @Nullable ReadableArray asArray() {
if (mArray == null) {
throw new IllegalStateException("This dynamic value has been recycled");
}
// NULLSAFE_FIXME[Return Not Nullable]
return mArray.getArray(mIndex);
}
@Override
public ReadableMap asMap() {
public @Nullable ReadableMap asMap() {
if (mArray == null) {
throw new IllegalStateException("This dynamic value has been recycled");
}
// NULLSAFE_FIXME[Return Not Nullable]
return mArray.getMap(mIndex);
}
@@ -36,7 +36,7 @@ public data class LengthPercentage(
}
ReadableType.String -> {
val s = dynamic.asString()
if (s.endsWith("%")) {
if (s != null && s.endsWith("%")) {
try {
val value = s.substring(0, s.length - 1).toFloat()
if (value >= 0f) {
@@ -76,7 +76,7 @@ public class ReactDrawerLayoutManager :
}
drawerPosition.type == ReadableType.String ->
setDrawerPositionInternal(view, drawerPosition.asString())
setDrawerPositionInternal(view, checkNotNull(drawerPosition.asString()))
else -> {
FLog.w(ReactConstants.TAG, "drawerPosition must be a string or int")
@@ -188,6 +188,10 @@ public open class ReactViewManager : ReactClippingViewManager<ReactViewGroup>()
when (hitSlop.type) {
ReadableType.Map -> {
val hitSlopMap = hitSlop.asMap()
if (hitSlopMap == null) {
view.setHitSlopRect(null)
return
}
view.setHitSlopRect(
Rect(
hitSlopMap.px("left"),