From 41c0af8caa0785c8f0fa130691fe1cb4007c417b Mon Sep 17 00:00:00 2001 From: emanuele-f Date: Tue, 26 Dec 2023 22:48:25 +0100 Subject: [PATCH] Fix possible crash in SkusAvailability.load Closes #373 --- .../remote_capture/model/SkusAvailability.java | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/app/src/main/java/com/emanuelef/remote_capture/model/SkusAvailability.java b/app/src/main/java/com/emanuelef/remote_capture/model/SkusAvailability.java index ea68fe1f1..0b746732a 100644 --- a/app/src/main/java/com/emanuelef/remote_capture/model/SkusAvailability.java +++ b/app/src/main/java/com/emanuelef/remote_capture/model/SkusAvailability.java @@ -24,7 +24,9 @@ import androidx.collection.ArraySet; import com.android.billingclient.api.SkuDetails; +import com.emanuelef.remote_capture.Log; import com.google.gson.Gson; +import com.google.gson.JsonSyntaxException; import java.io.Serializable; import java.util.HashSet; @@ -32,6 +34,7 @@ import java.util.List; public class SkusAvailability implements Serializable { + private final static String TAG = "SkusAvailability"; private final static String PREF_KEY = "available_skus"; private final ArraySet mSkus; @@ -42,7 +45,13 @@ private SkusAvailability() { public static SkusAvailability load(SharedPreferences prefs) { String serialized = prefs.getString(PREF_KEY, ""); Gson gson = new Gson(); - SkusAvailability obj = gson.fromJson(serialized, SkusAvailability.class); + SkusAvailability obj = null; + + try { + obj = gson.fromJson(serialized, SkusAvailability.class); + } catch (JsonSyntaxException e) { + Log.e(TAG, "SkusAvailability JSON load error: " + e); + } if(obj == null) obj = new SkusAvailability();