{"record":{"id":"e975f38e1d728385","repo":"nostra13/Android-Universal-Image-Loader","slug":"unexpected-journal-header-magic-version-v","errorCode":null,"errorMessage":"unexpected journal header: [{magic}, {version}, {valueCountString}, {blank}]","messagePattern":"unexpected journal header: \\[(.+?), (.+?), (.+?), (.+?)\\]","errorType":"exception","errorClass":"IOException","httpStatus":null,"severity":"error","filePath":"library/src/main/java/com/nostra13/universalimageloader/cache/disc/impl/ext/DiskLruCache.java","lineNumber":267,"sourceCode":"\t\tcache = new DiskLruCache(directory, appVersion, valueCount, maxSize, maxFileCount);\n\t\tcache.rebuildJournal();\n\t\treturn cache;\n\t}\n\n\tprivate void readJournal() throws IOException {\n\t\tStrictLineReader reader = new StrictLineReader(new FileInputStream(journalFile), Util.US_ASCII);\n\t\ttry {\n\t\t\tString magic = reader.readLine();\n\t\t\tString version = reader.readLine();\n\t\t\tString appVersionString = reader.readLine();\n\t\t\tString valueCountString = reader.readLine();\n\t\t\tString blank = reader.readLine();\n\t\t\tif (!MAGIC.equals(magic)\n\t\t\t\t\t|| !VERSION_1.equals(version)\n\t\t\t\t\t|| !Integer.toString(appVersion).equals(appVersionString)\n\t\t\t\t\t|| !Integer.toString(valueCount).equals(valueCountString)\n\t\t\t\t\t|| !\"\".equals(blank)) {\n\t\t\t\tthrow new IOException(\"unexpected journal header: [\" + magic + \", \" + version + \", \"\n\t\t\t\t\t\t+ valueCountString + \", \" + blank + \"]\");\n\t\t\t}\n\n\t\t\tint lineCount = 0;\n\t\t\twhile (true) {\n\t\t\t\ttry {\n\t\t\t\t\treadJournalLine(reader.readLine());\n\t\t\t\t\tlineCount++;\n\t\t\t\t} catch (EOFException endOfJournal) {\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t}\n\t\t\tredundantOpCount = lineCount - lruEntries.size();\n\t\t} finally {\n\t\t\tUtil.closeQuietly(reader);\n\t\t}\n\t}\n","sourceCodeStart":249,"sourceCodeEnd":285,"githubUrl":"https://github.com/nostra13/Android-Universal-Image-Loader/blob/ba33ec64d0daaa881d35852460e78c58d086bc18/library/src/main/java/com/nostra13/universalimageloader/cache/disc/impl/ext/DiskLruCache.java#L249-L285","documentation":"While opening an existing cache, DiskLruCache reads the journal file's five header lines and throws IOException if they don't exactly match the expected magic, version, appVersion, valueCount, and a blank line. The header ties the journal to a specific appVersion and valueCount, so any mismatch means the on-disk cache cannot be interpreted safely and is treated as corruption.","triggerScenarios":"DiskLruCache.open() on a directory whose journal was written by a different appVersion (e.g. you bumped the version code passed to open()), a different valueCount, a newer/older journal format, or a truncated/garbled journal file (partial write, device power loss, file synced from another cache).","commonSituations":"Shipping an app update that changes the appVersion argument; changing diskCache(... ) configuration (valueCount) while reusing the same cache directory; journal corruption after unclean shutdown; pointing two cache configurations at one directory.","solutions":["Delete the cache directory contents (or call cache.delete() if it can still open) and let the cache rebuild an empty journal.","Keep the appVersion passed to DiskLruCache.open() stable unless you intend to invalidate the cache.","Give each distinct cache configuration its own subdirectory so journals never mix."],"exampleFix":"// before\n// appVersion changed between releases -> header mismatch on old journal\nDiskLruCache cache = DiskLruCache.open(dir, 2, 1, maxSize, maxFileCount);\n\n// after\ntry {\n    cache = DiskLruCache.open(dir, 2, 1, maxSize, maxFileCount);\n} catch (IOException e) {\n    Util.deleteContents(dir); // journal unusable: wipe and rebuild\n    cache = DiskLruCache.open(dir, 2, 1, maxSize, maxFileCount);\n}","handlingStrategy":"fallback","validationCode":null,"typeGuard":null,"tryCatchPattern":"DiskLruCache cache;\ntry {\n    cache = DiskLruCache.open(dir, appVersion, valueCount, maxSize, maxFileCount);\n} catch (IOException headerMismatch) {\n    // journal unusable (appVersion/valueCount change or corruption): wipe and rebuild\n    Util.deleteContents(dir);\n    try {\n        cache = DiskLruCache.open(dir, appVersion, valueCount, maxSize, maxFileCount);\n    } catch (IOException retryFailed) {\n        throw new IllegalStateException(\"cannot rebuild disk cache at \" + dir, retryFailed);\n    }\n}","preventionTips":["Keep the appVersion argument stable across releases unless you intend cache invalidation.","Give each cache configuration (valueCount, format version) its own subdirectory.","Treat any IOException from open() as 'cache disposable' — disk cache is a cache, rebuilding is always safe."],"tags":["disk-cache","lru","journal","corruption","io","versioning"],"backgroundTag":null,"analyzedSha":"ba33ec64d0daaa881d35852460e78c58d086bc18","analyzedAt":"2026-08-14T15:41:15.893Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}