nostra13/Android-Universal-Image-Loader · error · IOException

unexpected journal line: {strings}

Error message

unexpected journal line: {strings}

What it means

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.

Source

Thrown at library/src/main/java/com/nostra13/universalimageloader/cache/disc/impl/ext/DiskLruCache.java:963

		}

		/** Set lengths using decimal numbers like "10123". */
		private void setLengths(String[] strings) throws IOException {
			if (strings.length != valueCount) {
				throw invalidLengths(strings);
			}

			try {
				for (int i = 0; i < strings.length; i++) {
					lengths[i] = Long.parseLong(strings[i]);
				}
			} catch (NumberFormatException e) {
				throw invalidLengths(strings);
			}
		}

		private IOException invalidLengths(String[] strings) throws IOException {
			throw new IOException("unexpected journal line: " + java.util.Arrays.toString(strings));
		}

		public File getCleanFile(int i) {
			return new File(directory, key + "." + i);
		}

		public File getDirtyFile(int i) {
			return new File(directory, key + "." + i + ".tmp");
		}
	}
}

View on GitHub (pinned to ba33ec64d0)

Solutions

  1. Catch IOException from DiskLruCache.open() and rebuild the cache: delete directory contents and reopen.
  2. Keep the cache directory excluded from backup/AV tooling that may rewrite files.
  3. Close/flush the cache cleanly on normal shutdown paths to minimize torn journal lines.

Example fix

// before
DiskLruCache cache = DiskLruCache.open(dir, 1, 1, maxSize, maxFileCount);

// after
DiskLruCache cache;
try {
    cache = DiskLruCache.open(dir, 1, 1, maxSize, maxFileCount);
} catch (IOException e) {
    Util.deleteContents(dir); // unparseable CLEAN lengths: start fresh
    cache = DiskLruCache.open(dir, 1, 1, maxSize, maxFileCount);
}
Defensive patterns

Strategy: fallback

Try / catch

try {
    cache = DiskLruCache.open(dir, appVersion, 1, maxSize, maxFileCount);
} catch (IOException badLengths) {
    Util.deleteContents(dir); // unparseable sizes: rebuild journal
    cache = DiskLruCache.open(dir, appVersion, 1, maxSize, maxFileCount);
}

Prevention

When it happens

Trigger: 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).

Common situations: 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.

Related errors


AI-assisted analysis of nostra13/Android-Universal-Image-Loader@ba33ec64d0 (2026-08-14). Data as JSON: /api/errors/bbd78548eef4bcc8. Report an issue: GitHub.