Skip to content

Commit dd9d26f

Browse files
修复空指针异常
cookie过期且cookies没有添加过该host的其他cookie的时候,会出现空指针的异常
1 parent 7f769fd commit dd9d26f

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

app/src/main/java/com/tamic/retrofitclient/net/PersistentCookieStore.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,8 @@ public void add(HttpUrl url, Cookie cookie) {
7676

7777
//讲cookies持久化到本地
7878
SharedPreferences.Editor prefsWriter = cookiePrefs.edit();
79-
prefsWriter.putString(url.host(), TextUtils.join(",", cookies.get(url.host()).keySet()));
79+
if (cookies.get(url.host()) != null && !cookies.get(url.host()).isEmpty())
80+
prefsWriter.putString(url.host(), TextUtils.join(",", cookies.get(url.host()).keySet()));
8081
prefsWriter.putString(name, encodeCookie(new SerializableOkHttpCookies(cookie)));
8182
prefsWriter.apply();
8283
}
@@ -198,4 +199,4 @@ protected byte[] hexStringToByteArray(String hexString) {
198199
}
199200
return data;
200201
}
201-
}
202+
}

0 commit comments

Comments
 (0)