mirror of
https://github.com/facebook/react-native.git
synced 2025-11-01 09:14:26 +00:00
fix WritableArray, WritableMap nullable annotations (#23397)
Summary:
Recently, I added nullable annotations to ReadableArray, ReadableMap, WritableArray, WritableMap and subclasses to improve Kotlin developer experience. But found that I made mistake with pushArray, pushMap, pushString method of WritableArray, and putArray, putMap, putString methods of WritableMap. This PR fixes previous mistake.
Excerpt from WritableNativeArray.cpp.
```cpp
void WritableNativeArray::pushString(jstring value) {
if (value == NULL) {
pushNull();
return;
}
throwIfConsumed();
array_.push_back(wrap_alias(value)->toStdString());
}
void WritableNativeArray::pushNativeArray(WritableNativeArray* otherArray) {
if (otherArray == NULL) {
pushNull();
return;
}
throwIfConsumed();
array_.push_back(otherArray->consume());
}
void WritableNativeArray::pushNativeMap(WritableNativeMap* map) {
if (map == NULL) {
pushNull();
return;
}
throwIfConsumed();
array_.push_back(map->consume());
}
```
Excerpt from WritableNativeMap.cpp
```cpp
void WritableNativeMap::putString(std::string key, alias_ref<jstring> val) {
if (!val) {
putNull(std::move(key));
return;
}
throwIfConsumed();
map_.insert(std::move(key), val->toString());
}
void WritableNativeMap::putNativeArray(std::string key, WritableNativeArray* otherArray) {
if (!otherArray) {
putNull(std::move(key));
return;
}
throwIfConsumed();
map_.insert(key, otherArray->consume());
}
void WritableNativeMap::putNativeMap(std::string key, WritableNativeMap *otherMap) {
if (!otherMap) {
putNull(std::move(key));
return;
}
throwIfConsumed();
map_.insert(std::move(key), otherMap->consume());
}
```
[Android] [Changed] - fix nullable annotations in WritableArray, WritableMap
Pull Request resolved: https://github.com/facebook/react-native/pull/23397
Differential Revision: D14044014
Pulled By: cpojer
fbshipit-source-id: c44ea2e097e7b1156223b516aa640a181f0d4a9b
This commit is contained in:
committed by
Facebook Github Bot
parent
77300ca91c
commit
7b33d6b0b9
@@ -12,6 +12,7 @@ import java.util.Iterator;
|
||||
import java.util.Map;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
/**
|
||||
* Java {@link HashMap} backed implementation of {@link ReadableMap} and {@link WritableMap}
|
||||
@@ -179,7 +180,7 @@ public class JavaOnlyMap implements ReadableMap, WritableMap {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void putString(@Nonnull String key, @Nonnull String value) {
|
||||
public void putString(@Nonnull String key, @Nullable String value) {
|
||||
mBackingMap.put(key, value);
|
||||
}
|
||||
|
||||
@@ -189,7 +190,7 @@ public class JavaOnlyMap implements ReadableMap, WritableMap {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void putMap(@Nonnull String key, @Nonnull WritableMap value) {
|
||||
public void putMap(@Nonnull String key, @Nullable WritableMap value) {
|
||||
mBackingMap.put(key, value);
|
||||
}
|
||||
|
||||
@@ -199,7 +200,7 @@ public class JavaOnlyMap implements ReadableMap, WritableMap {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void putArray(@Nonnull String key, @Nonnull WritableArray value) {
|
||||
public void putArray(@Nonnull String key, @Nullable WritableArray value) {
|
||||
mBackingMap.put(key, value);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user