{"record":{"id":"a4ff133a79e56f9a","repo":"nostra13/Android-Universal-Image-Loader","slug":"maxfilecount-0","errorCode":null,"errorMessage":"maxFileCount <= 0","messagePattern":"maxFileCount <= 0","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"library/src/main/java/com/nostra13/universalimageloader/cache/disc/impl/ext/DiskLruCache.java","lineNumber":209,"sourceCode":"\t}\n\n\t/**\n\t * Opens the cache in {@code directory}, creating a cache if none exists\n\t * there.\n\t *\n\t * @param directory a writable directory\n\t * @param valueCount the number of values per cache entry. Must be positive.\n\t * @param maxSize the maximum number of bytes this cache should use to store\n\t * @param maxFileCount the maximum file count this cache should store\n\t * @throws IOException if reading or writing the cache directory fails\n\t */\n\tpublic static DiskLruCache open(File directory, int appVersion, int valueCount, long maxSize, int maxFileCount)\n\t\t\tthrows IOException {\n\t\tif (maxSize <= 0) {\n\t\t\tthrow new IllegalArgumentException(\"maxSize <= 0\");\n\t\t}\n\t\tif (maxFileCount <= 0) {\n\t\t\tthrow new IllegalArgumentException(\"maxFileCount <= 0\");\n\t\t}\n\t\tif (valueCount <= 0) {\n\t\t\tthrow new IllegalArgumentException(\"valueCount <= 0\");\n\t\t}\n\n\t\t// If a bkp file exists, use it instead.\n\t\tFile backupFile = new File(directory, JOURNAL_FILE_BACKUP);\n\t\tif (backupFile.exists()) {\n\t\t\tFile journalFile = new File(directory, JOURNAL_FILE);\n\t\t\t// If journal file also exists just delete backup file.\n\t\t\tif (journalFile.exists()) {\n\t\t\t\tbackupFile.delete();\n\t\t\t} else {\n\t\t\t\trenameTo(backupFile, journalFile, false);\n\t\t\t}\n\t\t}\n\n\t\t// Prefer to pick up where we left off.","sourceCodeStart":191,"sourceCodeEnd":227,"githubUrl":"https://github.com/nostra13/Android-Universal-Image-Loader/blob/ba33ec64d0daaa881d35852460e78c58d086bc18/library/src/main/java/com/nostra13/universalimageloader/cache/disc/impl/ext/DiskLruCache.java#L191-L227","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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."],"exampleFix":"// before\nDiskLruCache.open(dir, appVersion, 1, maxSize, 0);\n\n// after\nDiskLruCache.open(dir, appVersion, 1, maxSize, Integer.MAX_VALUE);","handlingStrategy":"validation","validationCode":"int effectiveCount = (maxFileCount > 0) ? maxFileCount : Integer.MAX_VALUE;\nDiskLruCache.open(dir, appVersion, valueCount, maxSize, effectiveCount);","typeGuard":null,"tryCatchPattern":null,"preventionTips":["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."],"tags":["disk-cache","lru","validation","configuration"],"backgroundTag":null,"analyzedSha":"ba33ec64d0daaa881d35852460e78c58d086bc18","analyzedAt":"2026-08-14T15:41:15.893Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}