nostra13/Android-Universal-Image-Loader · error · IllegalArgumentException
maxFileCount must be a positive number
Error message
maxFileCount must be a positive number
What it means
ImageLoaderConfiguration.Builder.diskCacheFileCount(int) validates that the maximum number of files kept in the LruDiskCache is strictly positive; a zero or negative file count would prevent any caching and is treated as a configuration bug. Like diskCacheSize, this selects LruDiskCache and warns if a custom diskCache() was already set.
Source
Thrown at library/src/main/java/com/nostra13/universalimageloader/core/ImageLoaderConfiguration.java:451
return this;
}
/** @deprecated Use {@link #diskCacheFileCount(int)} instead */
@Deprecated
public Builder discCacheFileCount(int maxFileCount) {
return diskCacheFileCount(maxFileCount);
}
/**
* Sets maximum file count in disk cache directory.<br />
* By default: disk cache is unlimited.<br />
* <b>NOTE:</b> If you use this method then
* {@link com.nostra13.universalimageloader.cache.disc.impl.ext.LruDiskCache LruDiskCache}
* will be used as disk cache. You can use {@link #diskCache(DiskCache)} method for introduction your own
* implementation of {@link DiskCache}
*/
public Builder diskCacheFileCount(int maxFileCount) {
if (maxFileCount <= 0) throw new IllegalArgumentException("maxFileCount must be a positive number");
if (diskCache != null) {
L.w(WARNING_OVERLAP_DISK_CACHE_PARAMS);
}
this.diskCacheFileCount = maxFileCount;
return this;
}
/** @deprecated Use {@link #diskCacheFileNameGenerator(com.nostra13.universalimageloader.cache.disc.naming.FileNameGenerator)} */
@Deprecated
public Builder discCacheFileNameGenerator(FileNameGenerator fileNameGenerator) {
return diskCacheFileNameGenerator(fileNameGenerator);
}
/**
* Sets name generator for files cached in disk cache.<br />
* Default value -View on GitHub (pinned to ba33ec64d0)
Solutions
- Pass a positive count: diskCacheFileCount(200)
- Clamp dynamic values: Math.max(1, count)
- If file-count limiting is unwanted, omit the call entirely (unlimited by default)
Example fix
// before
builder.diskCacheFileCount(prefs.getInt("cache_files", 0)); // throws
// after
builder.diskCacheFileCount(Math.max(1, prefs.getInt("cache_files", 200))); Defensive patterns
Strategy: validation
Validate before calling
int count = Math.max(1, configuredFileCount); builder.diskCacheFileCount(count);
Type guard
static boolean isValidFileCount(int n) {
return n > 0;
} Prevention
- Give 'max cached files' settings a positive default (e.g. 200)
- Clamp preferences/remote-config values before passing to the builder
- Omit the call when file-count limiting is not needed
When it happens
Trigger: diskCacheFileCount(0) or negative; a count read from preferences/remote config that was never set and defaults to 0.
Common situations: Settings screen 'max cached files' field left at 0; deserialized config objects with unset int fields defaulting to 0; tests exercising builder validation with edge values.
Related errors
- maxSize <= 0
- maxFileCount <= 0
- valueCount <= 0
- cacheMaxSize argument must be positive number
- cacheMaxFileCount argument must be positive number
AI-assisted analysis of nostra13/Android-Universal-Image-Loader@ba33ec64d0 (2026-08-14).
Data as JSON: /api/errors/e9ab3c0eed8cec2e.
Report an issue: GitHub.