Skip to content

Commit

Permalink
fix(firestore): NullPointerException in getDocument(...) on Andro…
Browse files Browse the repository at this point in the history
…id (#471)
  • Loading branch information
robingenz committed Oct 18, 2023
1 parent 5e4a2c8 commit 5c720b5
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 7 deletions.
5 changes: 5 additions & 0 deletions .changeset/tame-parents-burn.md
@@ -0,0 +1,5 @@
---
'@capacitor-firebase/firestore': patch
---

fix(android): `NullPointerException` in `getDocument(...)`
Expand Up @@ -77,12 +77,8 @@ public void getDocument(@NonNull GetDocumentOptions options, @NonNull NonEmptyRe
.get()
.addOnSuccessListener(
documentSnapshot -> {
if (documentSnapshot.exists()) {
GetDocumentResult result = new GetDocumentResult(documentSnapshot);
callback.success(result);
} else {
callback.success(null);
}
GetDocumentResult result = new GetDocumentResult(documentSnapshot);
callback.success(result);
}
)
.addOnFailureListener(exception -> callback.error(exception));
Expand Down
Expand Up @@ -4,6 +4,7 @@
import com.google.firebase.firestore.DocumentSnapshot;
import io.capawesome.capacitorjs.plugins.firebase.firestore.FirebaseFirestoreHelper;
import io.capawesome.capacitorjs.plugins.firebase.firestore.interfaces.Result;
import org.json.JSONObject;

public class GetDocumentResult implements Result {

Expand All @@ -14,7 +15,12 @@ public GetDocumentResult(DocumentSnapshot documentSnapshot) {
}

public JSObject toJSObject() {
JSObject snapshotDataResult = FirebaseFirestoreHelper.createJSObjectFromMap(documentSnapshot.getData());
Object snapshotDataResult;
if (documentSnapshot.exists()) {
snapshotDataResult = FirebaseFirestoreHelper.createJSObjectFromMap(documentSnapshot.getData());
} else {
snapshotDataResult = JSONObject.NULL;
}

JSObject snapshotResult = new JSObject();
snapshotResult.put("id", documentSnapshot.getId());
Expand Down

0 comments on commit 5c720b5

Please sign in to comment.