From e26b0961f2e56c9ce61837809bf7c47b6631dc46 Mon Sep 17 00:00:00 2001 From: Gideon Okuro Date: Mon, 18 Sep 2023 20:03:18 +0300 Subject: [PATCH] sync: harden realm towards null exceptions (fixes #2506) (#2507) Co-authored-by: dogi --- app/build.gradle | 4 ++-- .../planet/myplanet/service/UploadManager.java | 18 +++++++++++++----- 2 files changed, 15 insertions(+), 7 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index 1bfe6ab3f8..9408445145 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -10,8 +10,8 @@ android { applicationId "org.ole.planet.myplanet" minSdkVersion 21 targetSdkVersion 34 - versionCode 1043 - versionName "0.10.43" + versionCode 1044 + versionName "0.10.44" ndkVersion '21.3.6528147' testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" vectorDrawables.useSupportLibrary = true diff --git a/app/src/main/java/org/ole/planet/myplanet/service/UploadManager.java b/app/src/main/java/org/ole/planet/myplanet/service/UploadManager.java index 313467d812..3169b2ab4d 100644 --- a/app/src/main/java/org/ole/planet/myplanet/service/UploadManager.java +++ b/app/src/main/java/org/ole/planet/myplanet/service/UploadManager.java @@ -6,6 +6,7 @@ import com.google.gson.Gson; import com.google.gson.JsonArray; +import com.google.gson.JsonElement; import com.google.gson.JsonObject; import org.ole.planet.myplanet.MainApplication; @@ -232,14 +233,21 @@ public void uploadFeedback(final SuccessListener listener) { try { Response res; res = apiInterface.postDoc(Utilities.getHeader(), "application/json", Utilities.getUrl() + "/feedback", RealmFeedback.serializeFeedback(feedback)).execute(); - if (res.body() != null) { - Utilities.log(new Gson().toJson(res.body())); - JsonObject r = (JsonObject) res.body(); - feedback.set_rev(r.get("rev").getAsString()); - feedback.set_id(r.get("id").getAsString()); + JsonObject r = (JsonObject) res.body(); + if (r != null) { + JsonElement revElement = r.get("rev"); + JsonElement idElement = r.get("id"); + + if (revElement != null && idElement != null) { + feedback.set_rev(revElement.getAsString()); + feedback.set_id(idElement.getAsString()); + } else { + Utilities.log("Missing 'rev' or 'id' elements in the JSON response"); + } } else { Utilities.log("ERRRRRRRR " + res.errorBody().string()); } + } catch (IOException e) { e.printStackTrace(); }