mirror of
https://github.com/facebook/react-native.git
synced 2025-11-01 09:14:26 +00:00
fix nullsafe FIXMES for DynamicFromObject.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 DynamicFromObject.java nullsafe Reviewed By: alanleedev Differential Revision: D72384066 fbshipit-source-id: 6f187f8a87a2c5d239c671880404eb81f0e22d3e
This commit is contained in:
committed by
Facebook GitHub Bot
parent
c692a1185a
commit
a0e3490ff5
+20
-6
@@ -9,9 +9,11 @@ package com.facebook.react.bridge;
|
||||
|
||||
import androidx.annotation.Nullable;
|
||||
import com.facebook.common.logging.FLog;
|
||||
import com.facebook.infer.annotation.Nullsafe;
|
||||
import com.facebook.react.common.ReactConstants;
|
||||
|
||||
/** Implementation of Dynamic wrapping a ReadableArray. */
|
||||
@Nullsafe(Nullsafe.Mode.LOCAL)
|
||||
public class DynamicFromObject implements Dynamic {
|
||||
private @Nullable Object mObject;
|
||||
|
||||
@@ -31,38 +33,50 @@ public class DynamicFromObject implements Dynamic {
|
||||
|
||||
@Override
|
||||
public boolean asBoolean() {
|
||||
// NULLSAFE_FIXME[Nullable Dereference]
|
||||
if (mObject == null || !(mObject instanceof Boolean)) {
|
||||
throw new ClassCastException("Dynamic value from Object is not a boolean");
|
||||
}
|
||||
return (boolean) mObject;
|
||||
}
|
||||
|
||||
@Override
|
||||
public double asDouble() {
|
||||
// NULLSAFE_FIXME[Nullable Dereference]
|
||||
if (mObject == null || !(mObject instanceof Number)) {
|
||||
throw new ClassCastException("Dynamic value from Object is not a number");
|
||||
}
|
||||
return (double) mObject;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int asInt() {
|
||||
if (mObject == null || !(mObject instanceof Number)) {
|
||||
throw new ClassCastException("Dynamic value from Object is not a number");
|
||||
}
|
||||
// Numbers from JS are always Doubles
|
||||
// NULLSAFE_FIXME[Nullable Dereference]
|
||||
return ((Double) mObject).intValue();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String asString() {
|
||||
// NULLSAFE_FIXME[Return Not Nullable]
|
||||
if (mObject == null || !(mObject instanceof String)) {
|
||||
throw new ClassCastException("Dynamic value from Object is not a string");
|
||||
}
|
||||
return (String) mObject;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ReadableArray asArray() {
|
||||
// NULLSAFE_FIXME[Return Not Nullable]
|
||||
if (mObject == null || !(mObject instanceof ReadableArray)) {
|
||||
throw new ClassCastException("Dynamic value from Object is not a ReadableArray");
|
||||
}
|
||||
return (ReadableArray) mObject;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ReadableMap asMap() {
|
||||
// NULLSAFE_FIXME[Return Not Nullable]
|
||||
if (mObject == null || !(mObject instanceof ReadableMap)) {
|
||||
throw new ClassCastException("Dynamic value from Object is not a ReadableMap");
|
||||
}
|
||||
return (ReadableMap) mObject;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user