{"record":{"id":"f29f500ccd1222dd","repo":"bumptech/glide","slug":"size-mismatch-expected-to-be-able-to-evict-at-lea","errorCode":null,"errorMessage":"Size mismatch, expected to be able to evict at least {} bytes, but only found {} bytes worth of entries!","messagePattern":"Size mismatch, expected to be able to evict at least (.+?) bytes, but only found (.+?) bytes worth of entries!","errorType":"exception","errorClass":"IllegalStateException","httpStatus":null,"severity":"error","filePath":"integration/sqljournaldiskcache/src/main/java/com/bumptech/glide/integration/sqljournaldiskcache/Journal.java","lineNumber":235,"sourceCode":"          String key = cursor.getString(keyIdx);\n          keys.add(key);\n\n          long sizeBytes = cursor.getLong(sizeIdx);\n          currentByteCount += sizeBytes;\n        }\n        isOutOfEntries = cursor.getCount() < LRU_BATCH_SIZE;\n      } finally {\n        cursor.close();\n      }\n      currentOffset += LRU_BATCH_SIZE;\n    }\n\n    // TODO(judds): for a sufficiently large file or small cache size and a failed attempt to commit\n    // a put, this can happen because our journal size will temporarily not match our File size.\n    // If this becomes an issue, we can safely just clear the cache here instead of throwing because\n    // we were about to delete all the files anyway.\n    if (isOutOfEntries && currentByteCount < targetByteCount) {\n      throw new IllegalStateException(\n          \"Size mismatch\"\n              + \", expected to be able to evict at least \"\n              + targetByteCount\n              + \" bytes\"\n              + \", but only found \"\n              + currentByteCount\n              + \" bytes worth of entries!\");\n    }\n\n    return keys;\n  }\n\n  List<String> getStaleEntries(long staleTimeThresholdMs) {\n    SQLiteDatabase db = dbHelper.getReadableDatabase();\n    List<String> keys = new ArrayList<>();\n    long currentRowId = 0L;\n    boolean isOutOfEntries = false;\n    while (!isOutOfEntries) {","sourceCodeStart":217,"sourceCodeEnd":253,"githubUrl":"https://github.com/bumptech/glide/blob/eb14a895d8f866e6a08c3e19d50ea3bd2c12c20a/integration/sqljournaldiskcache/src/main/java/com/bumptech/glide/integration/sqljournaldiskcache/Journal.java#L217-L253","documentation":"Thrown by Journal.getLeastRecentlyUsed() when it has exhausted all LRU-batched entries (isOutOfEntries) but the cumulative bytes of found entries (currentByteCount) is still below the targetByteCount the caller asked to evict. The journal's recorded size claims more bytes exist than the rows actually account for.","triggerScenarios":"The cursor loop reads entries in LRU_BATCH_SIZE chunks; after the last batch isOutOfEntries becomes true, yet currentByteCount < targetByteCount, so the guard at line 235 fires. This is a size-accounting mismatch between journal metadata and the rows queryable for eviction.","commonSituations":"A failed/partial commit left a journal row whose size was decremented but whose file still contributes, or vice versa; the on-disk file size differs from the summed entry sizes after an interrupted put. The source TODO notes this can happen for large files/small caches after a failed commit.","solutions":["Clear the disk cache to force a clean journal rebuild (the code comment notes clearing is safe here since eviction was about to delete everything anyway).","Upgrade the sqljournaldiskcache integration for size-tracking robustness.","Investigate prior write/commit failures (device ran low on storage, process killed mid-write) that could have desynced sizes.","Ensure no external process alters files in the cache directory."],"exampleFix":null,"handlingStrategy":"fallback","validationCode":null,"typeGuard":null,"tryCatchPattern":"try {\n  diskCache.put(key, data)\n} catch (e: IllegalStateException) {\n  if (e.message?.contains(\"Size mismatch\") == true) {\n    diskCache.clear() // safe per code comment; eviction was about to delete all\n  } else throw e\n}","preventionTips":["Treat size-mismatch as a signal to reset the journal via clear().","Investigate prior write/commit failures that desync sizes.","Prevent concurrent external access to the cache directory."],"tags":["sqljournaldiskcache","integration","journal","lru","size-mismatch","corruption","runtime"],"backgroundTag":null,"analyzedSha":"eb14a895d8f866e6a08c3e19d50ea3bd2c12c20a","analyzedAt":"2026-08-14T01:43:54.821Z","schemaVersion":2},"datasetVersion":"2026-08-14T05:17:29.042Z"}