Skip to content

Commit

Permalink
Fix possible crash in SkusAvailability.load
Browse files Browse the repository at this point in the history
Closes #373
  • Loading branch information
emanuele-f committed Dec 26, 2023
1 parent 37c4ce6 commit 41c0af8
Showing 1 changed file with 10 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,17 @@
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;
import java.util.Iterator;
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<String> mSkus;

Expand All @@ -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();
Expand Down

0 comments on commit 41c0af8

Please sign in to comment.