{"record":{"id":"bbd78548eef4bcc8","repo":"nostra13/Android-Universal-Image-Loader","slug":"unexpected-journal-line-strings","errorCode":null,"errorMessage":"unexpected journal line: {strings}","messagePattern":"unexpected journal line: (.+?)","errorType":"exception","errorClass":"IOException","httpStatus":null,"severity":"error","filePath":"library/src/main/java/com/nostra13/universalimageloader/cache/disc/impl/ext/DiskLruCache.java","lineNumber":963,"sourceCode":"\t\t}\n\n\t\t/** Set lengths using decimal numbers like \"10123\". */\n\t\tprivate void setLengths(String[] strings) throws IOException {\n\t\t\tif (strings.length != valueCount) {\n\t\t\t\tthrow invalidLengths(strings);\n\t\t\t}\n\n\t\t\ttry {\n\t\t\t\tfor (int i = 0; i < strings.length; i++) {\n\t\t\t\t\tlengths[i] = Long.parseLong(strings[i]);\n\t\t\t\t}\n\t\t\t} catch (NumberFormatException e) {\n\t\t\t\tthrow invalidLengths(strings);\n\t\t\t}\n\t\t}\n\n\t\tprivate IOException invalidLengths(String[] strings) throws IOException {\n\t\t\tthrow new IOException(\"unexpected journal line: \" + java.util.Arrays.toString(strings));\n\t\t}\n\n\t\tpublic File getCleanFile(int i) {\n\t\t\treturn new File(directory, key + \".\" + i);\n\t\t}\n\n\t\tpublic File getDirtyFile(int i) {\n\t\t\treturn new File(directory, key + \".\" + i + \".tmp\");\n\t\t}\n\t}\n}\n","sourceCodeStart":945,"sourceCodeEnd":975,"githubUrl":"https://github.com/nostra13/Android-Universal-Image-Loader/blob/ba33ec64d0daaa881d35852460e78c58d086bc18/library/src/main/java/com/nostra13/universalimageloader/cache/disc/impl/ext/DiskLruCache.java#L945-L975","documentation":"IOException from DiskLruCache.Entry.invalidLengths, reached when a CLEAN journal line's per-value length tokens fail Long.parseLong. CLEAN lines carry the file sizes as decimal numbers; a non-numeric token means the journal line is corrupt, and the cache refuses to open rather than misreport entry sizes.","triggerScenarios":"Journal replay hits a CLEAN line whose length column is garbled — partial writes from a crash mid-journal-append, bit rot, or an incompatible writer producing non-numeric lengths (e.g. floats or empty tokens from 'key. ' with trailing space then nothing).","commonSituations":"Unclean shutdown leaving a torn CLEAN line; cache directories edited by hand or scanned/modified by backup/antivirus tools; flash corruption on cheap SD storage.","solutions":["Catch IOException from DiskLruCache.open() and rebuild the cache: delete directory contents and reopen.","Keep the cache directory excluded from backup/AV tooling that may rewrite files.","Close/flush the cache cleanly on normal shutdown paths to minimize torn journal lines."],"exampleFix":"// before\nDiskLruCache cache = DiskLruCache.open(dir, 1, 1, maxSize, maxFileCount);\n\n// after\nDiskLruCache cache;\ntry {\n    cache = DiskLruCache.open(dir, 1, 1, maxSize, maxFileCount);\n} catch (IOException e) {\n    Util.deleteContents(dir); // unparseable CLEAN lengths: start fresh\n    cache = DiskLruCache.open(dir, 1, 1, maxSize, maxFileCount);\n}","handlingStrategy":"fallback","validationCode":null,"typeGuard":null,"tryCatchPattern":"try {\n    cache = DiskLruCache.open(dir, appVersion, 1, maxSize, maxFileCount);\n} catch (IOException badLengths) {\n    Util.deleteContents(dir); // unparseable sizes: rebuild journal\n    cache = DiskLruCache.open(dir, appVersion, 1, maxSize, maxFileCount);\n}","preventionTips":["Exclude cache directories from backup/antivirus tools that may rewrite journal files.","Flush/close the cache cleanly at app shutdown to avoid torn CLEAN lines.","Treat any journal IOException as recoverable-by-wipe; never try to patch journal lines."],"tags":["disk-cache","lru","journal","corruption","io","parsing"],"backgroundTag":null,"analyzedSha":"ba33ec64d0daaa881d35852460e78c58d086bc18","analyzedAt":"2026-08-14T15:41:15.893Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}