nostra13/Android-Universal-Image-Loader · error · IllegalArgumentException
maxFileCount <= 0
Error message
maxFileCount <= 0
What it means
DiskLruCache.open() throws IllegalArgumentException when maxFileCount is zero or negative. This variant of DiskLruCache enforces both a byte cap (maxSize) and a file-count cap, and a non-positive count cap is rejected outright. As with maxSize, the '0 = unlimited' convention is handled by the LruDiskCache wrapper, not here.
Source
Thrown at library/src/main/java/com/nostra13/universalimageloader/cache/disc/impl/ext/DiskLruCache.java:209
}
/**
* 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.View on GitHub (pinned to ba33ec64d0)
Solutions
- Pass a strictly positive file-count cap, e.g. 10000.
- For effectively unlimited, pass Integer.MAX_VALUE (what LruDiskCache uses when cacheMaxFileCount == 0).
- Use LruDiskCache/ImageLoaderConfiguration.diskCacheFileCount(...) instead of calling open() directly so 0 is normalized.
Example fix
// before DiskLruCache.open(dir, appVersion, 1, maxSize, 0); // after DiskLruCache.open(dir, appVersion, 1, maxSize, Integer.MAX_VALUE);
Defensive patterns
Strategy: validation
Validate before calling
int effectiveCount = (maxFileCount > 0) ? maxFileCount : Integer.MAX_VALUE; DiskLruCache.open(dir, appVersion, valueCount, maxSize, effectiveCount);
Prevention
- When migrating from the 4-arg open(), decide the file-count cap explicitly instead of defaulting it to 0.
- Clamp config-driven counts with Math.max(1, count).
- Use LruDiskCache to get 0-means-unlimited semantics for free.
When it happens
Trigger: Calling DiskLruCache.open(directory, appVersion, valueCount, maxSize, 0) or with a negative count. Happens when callers reuse argument lists from the older 4-arg open() that had no file-count parameter.
Common situations: Migrating from an older UniversalImageLoader version whose DiskLruCache.open lacked maxFileCount and defaulting the new parameter to 0; config-driven values where the count field is unset and defaults to 0.
Related errors
- maxSize <= 0
- valueCount <= 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/a4ff133a79e56f9a.
Report an issue: GitHub.