From 3fa82cdba758a4ab9ed13237266ad2246e52e45d Mon Sep 17 00:00:00 2001 From: Blatzar <46196380+Blatzar@users.noreply.github.com> Date: Mon, 5 Dec 2022 16:09:51 +0100 Subject: [PATCH] Probably fixed a very weird exception --- .../java/com/lagradost/cloudstream3/ui/APIRepository.kt | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/app/src/main/java/com/lagradost/cloudstream3/ui/APIRepository.kt b/app/src/main/java/com/lagradost/cloudstream3/ui/APIRepository.kt index 2c50a6c6..227c2f25 100644 --- a/app/src/main/java/com/lagradost/cloudstream3/ui/APIRepository.kt +++ b/app/src/main/java/com/lagradost/cloudstream3/ui/APIRepository.kt @@ -38,8 +38,9 @@ class APIRepository(val api: MainAPI) { val hash: Pair ) - - private val cache: ArrayList = arrayListOf() + // This really does not need to be Nullable but it can crash otherwise, probably caused by replacing items while looping over them. + // "Attempt to invoke .... getHash() on a null object reference" + private val cache: ArrayList = arrayListOf() private var cacheIndex: Int = 0 const val cacheSize = 20 } @@ -60,7 +61,7 @@ class APIRepository(val api: MainAPI) { for (item in cache) { // 10 min save - if (item.hash == lookingForHash && (unixTime - item.unixTime) < 60 * 10) { + if (item?.hash == lookingForHash && (unixTime - item.unixTime) < 60 * 10) { return@safeApiCall item.response } }