File tree Expand file tree Collapse file tree
app/src/main/java/com/theveloper/pixelplay/data/telegram Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -189,8 +189,13 @@ class TelegramCacheManager @Inject constructor(
189189 return @launch // Within limits
190190 }
191191
192- // Sort by last modified (oldest first) for LRU eviction
193- embeddedArtFiles.sortBy { it.lastModified() }
192+ // Sort by last modified (oldest first) for LRU eviction.
193+ // Snapshot timestamps before sorting — reading lastModified() inside the
194+ // comparator on every pairwise call lets another coroutine's setLastModified()
195+ // change the value mid-sort, violating TimSort's comparator contract and
196+ // throwing "Comparison method violates its general contract!".
197+ val snapshots = embeddedArtFiles.associateWith { it.lastModified() }
198+ embeddedArtFiles.sortWith(compareBy { snapshots[it] })
194199
195200 var deletedCount = 0
196201 for (file in embeddedArtFiles) {
You can’t perform that action at this time.
0 commit comments