Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -189,8 +189,13 @@ class TelegramCacheManager @Inject constructor(
return@launch // Within limits
}

// Sort by last modified (oldest first) for LRU eviction
embeddedArtFiles.sortBy { it.lastModified() }
// Sort by last modified (oldest first) for LRU eviction.
// Snapshot timestamps before sorting — reading lastModified() inside the
// comparator on every pairwise call lets another coroutine's setLastModified()
// change the value mid-sort, violating TimSort's comparator contract and
// throwing "Comparison method violates its general contract!".
val snapshots = embeddedArtFiles.associateWith { it.lastModified() }
embeddedArtFiles.sortWith(compareBy { snapshots[it] })

var deletedCount = 0
for (file in embeddedArtFiles) {
Expand Down
Loading