Skip to content

Commit 0c7882a

Browse files
committed
Code improvement: Handling edge case when handling cache
1 parent 18e0db6 commit 0c7882a

File tree

1 file changed

+13
-8
lines changed

1 file changed

+13
-8
lines changed

helpstack/src/com/tenmiles/helpstack/logic/HSSource.java

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -105,10 +105,6 @@ private HSSource(Context context) {
105105
setGear(HSHelpStack.getInstance(context).getGear());
106106
mRequestQueue = HSHelpStack.getInstance(context).getRequestQueue();
107107

108-
cachedTicket = new HSCachedTicket();
109-
cachedUser = new HSCachedUser();
110-
draftObject = new HSDraft();
111-
112108
refreshFieldsFromCache();
113109
}
114110

@@ -452,7 +448,10 @@ protected void doReadTicketsFromCache() {
452448

453449
String json = readJsonFromFile(ticketFile);
454450

455-
if (json != null) {
451+
if (json == null) {
452+
cachedTicket = new HSCachedTicket();
453+
}
454+
else {
456455
Gson gson = new Gson();
457456
cachedTicket = gson.fromJson(json, HSCachedTicket.class);
458457
}
@@ -466,7 +465,10 @@ protected void doReadUserFromCache() {
466465

467466
String json = readJsonFromFile(userFile);
468467

469-
if (json != null) {
468+
if (json == null) {
469+
cachedUser = new HSCachedUser();
470+
}
471+
else {
470472
Gson gson = new Gson();
471473
cachedUser = gson.fromJson(json, HSCachedUser.class);
472474
}
@@ -477,8 +479,11 @@ protected void doReadDraftFromCache() {
477479

478480
String json = readJsonFromFile(draftFile);
479481

480-
if (json != null) {
481-
Gson gson = new Gson();
482+
if (json == null) {
483+
draftObject = new HSDraft();
484+
}
485+
else {
486+
Gson gson = new Gson();
482487
draftObject = gson.fromJson(json, HSDraft.class);
483488
}
484489
}

0 commit comments

Comments
 (0)