Skip to content
This repository was archived by the owner on Feb 4, 2025. It is now read-only.

Commit 2d90f9a

Browse files
authored
Merge pull request #3047 from wordpress-mobile/issue/3046-atomic-cookie-numberformatexception
[FluxC] Catch NumberFormatException in PrivateAtomicCookie
2 parents 56cd665 + be56f14 commit 2d90f9a

File tree

1 file changed

+12
-6
lines changed

1 file changed

+12
-6
lines changed

fluxc/src/main/java/org/wordpress/android/fluxc/network/rest/wpcom/site/PrivateAtomicCookie.kt

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -33,13 +33,19 @@ class PrivateAtomicCookie
3333
}
3434

3535
private fun isExpiringSoon(): Boolean {
36-
if (!exists()) {
37-
return true
36+
return if (!exists()) {
37+
true
38+
} else {
39+
try {
40+
val cookieExpiration: Long = cookie!!.expires.toLong()
41+
val currentTime = (System.currentTimeMillis() / MILLIS)
42+
currentTime + COOKIE_EXPIRATION_THRESHOLD >= cookieExpiration
43+
} catch (e: NumberFormatException) {
44+
// we ran into a situation where cookie!!.expires contained "false" resulting
45+
// in an exception attempting to convert it to a long
46+
false
47+
}
3848
}
39-
val cookieExpiration: Long = cookie!!.expires.toLong()
40-
val currentTime = (System.currentTimeMillis() / MILLIS)
41-
42-
return currentTime + COOKIE_EXPIRATION_THRESHOLD >= cookieExpiration
4349
}
4450

4551
fun exists(): Boolean {

0 commit comments

Comments
 (0)