nostra13/Android-Universal-Image-Loader · error · IllegalArgumentException
valueCount <= 0
Error message
valueCount <= 0
What it means
DiskLruCache.open() throws IllegalArgumentException when valueCount is zero or negative. valueCount defines how many files each cache entry owns (keys map to valueCount files named key.0..key.N-1); at least one value per entry is required. The library itself always calls open() with valueCount = 1.
Source
Thrown at library/src/main/java/com/nostra13/universalimageloader/cache/disc/impl/ext/DiskLruCache.java:212
* Opens the cache in {@code directory}, creating a cache if none exists
* there.
*
* @param directory a writable directory
* @param valueCount the number of values per cache entry. Must be positive.
* @param maxSize the maximum number of bytes this cache should use to store
* @param maxFileCount the maximum file count this cache should store
* @throws IOException if reading or writing the cache directory fails
*/
public static DiskLruCache open(File directory, int appVersion, int valueCount, long maxSize, int maxFileCount)
throws IOException {
if (maxSize <= 0) {
throw new IllegalArgumentException("maxSize <= 0");
}
if (maxFileCount <= 0) {
throw new IllegalArgumentException("maxFileCount <= 0");
}
if (valueCount <= 0) {
throw new IllegalArgumentException("valueCount <= 0");
}
// If a bkp file exists, use it instead.
File backupFile = new File(directory, JOURNAL_FILE_BACKUP);
if (backupFile.exists()) {
File journalFile = new File(directory, JOURNAL_FILE);
// If journal file also exists just delete backup file.
if (journalFile.exists()) {
backupFile.delete();
} else {
renameTo(backupFile, journalFile, false);
}
}
// Prefer to pick up where we left off.
DiskLruCache cache = new DiskLruCache(directory, appVersion, valueCount, maxSize, maxFileCount);
if (cache.journalFile.exists()) {
try {View on GitHub (pinned to ba33ec64d0)
Solutions
- Pass 1 for valueCount unless you deliberately implement multi-file entries.
- Audit custom DiskLruCache wrappers for hardcoded zeros in the open() call.
- Prefer LruDiskCache, which always uses valueCount = 1 internally.
Example fix
// before DiskLruCache.open(dir, appVersion, 0, maxSize, maxFileCount); // after DiskLruCache.open(dir, appVersion, 1, maxSize, maxFileCount);
Defensive patterns
Strategy: validation
Validate before calling
if (valueCount <= 0) throw new IllegalArgumentException("valueCount must be >= 1, got " + valueCount);
DiskLruCache.open(dir, appVersion, valueCount, maxSize, maxFileCount); Prevention
- Hardcode valueCount = 1 unless you implement multi-file entries deliberately.
- Don't zero out parameters you don't understand when copy-pasting open() calls.
- Let LruDiskCache manage open() — it always passes 1.
When it happens
Trigger: Calling DiskLruCache.open(directory, appVersion, 0, maxSize, maxFileCount) or with a negative valueCount. In this codebase the only production call site (LruDiskCache.initDiskCache) passes 1, so hitting it means custom code called open() directly with a computed or hardcoded 0.
Common situations: Copy-pasting an open() call and zeroing parameters you don't understand; deriving valueCount from a multi-file entry scheme that computed 0 entries; adapting an older sample that omitted the parameter.
Related errors
- maxSize <= 0
- maxFileCount <= 0
- cacheMaxSize argument must be positive number
- cacheMaxFileCount argument must be positive number
- keys must match regex [a-z0-9_-]{1,64}: "{key}"
AI-assisted analysis of nostra13/Android-Universal-Image-Loader@ba33ec64d0 (2026-08-14).
Data as JSON: /api/errors/0b294ad00351a239.
Report an issue: GitHub.