Skip to content

Commit 70e9e44

Browse files
wilhuffa-maurice
authored andcommitted
Fix DocumentSnapshot for non-existent documents in C++ and Unity
There are two fixes here: * In Android C++, a non-existent document is returned as a null map; translate that to an empty map in C++ * In Unity, handle non-existent documents specially to avoid returning an empty Dictionary to C# users (where null is the expected value). PiperOrigin-RevId: 347416592
1 parent 0d779c4 commit 70e9e44

File tree

2 files changed

+92
-96
lines changed

2 files changed

+92
-96
lines changed

firestore/src/android/document_snapshot_android.cc

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,13 @@ MapFieldValue DocumentSnapshotInternal::GetData(
8585
Env env = GetEnv();
8686
Local<Object> java_stb = ServerTimestampBehaviorInternal::Create(env, stb);
8787
Local<Object> java_data = env.Call(obj_, kGetData, java_stb);
88+
89+
if (!java_data) {
90+
// If the document doesn't exist, Android returns a null Map. In C++, the
91+
// map is returned by value, so translate this case to an empty map.
92+
return MapFieldValue();
93+
}
94+
8895
return FieldValueInternal(java_data).map_value();
8996
}
9097

0 commit comments

Comments
 (0)