{"record":{"id":"e9ab3c0eed8cec2e","repo":"nostra13/Android-Universal-Image-Loader","slug":"maxfilecount-must-be-a-positive-number","errorCode":null,"errorMessage":"maxFileCount must be a positive number","messagePattern":"maxFileCount must be a positive number","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"library/src/main/java/com/nostra13/universalimageloader/core/ImageLoaderConfiguration.java","lineNumber":451,"sourceCode":"\t\t\treturn this;\n\t\t}\n\n\t\t/** @deprecated Use {@link #diskCacheFileCount(int)} instead */\n\t\t@Deprecated\n\t\tpublic Builder discCacheFileCount(int maxFileCount) {\n\t\t\treturn diskCacheFileCount(maxFileCount);\n\t\t}\n\n\t\t/**\n\t\t * Sets maximum file count in disk cache directory.<br />\n\t\t * By default: disk cache is unlimited.<br />\n\t\t * <b>NOTE:</b> If you use this method then\n\t\t * {@link com.nostra13.universalimageloader.cache.disc.impl.ext.LruDiskCache LruDiskCache}\n\t\t * will be used as disk cache. You can use {@link #diskCache(DiskCache)} method for introduction your own\n\t\t * implementation of {@link DiskCache}\n\t\t */\n\t\tpublic Builder diskCacheFileCount(int maxFileCount) {\n\t\t\tif (maxFileCount <= 0) throw new IllegalArgumentException(\"maxFileCount must be a positive number\");\n\n\t\t\tif (diskCache != null) {\n\t\t\t\tL.w(WARNING_OVERLAP_DISK_CACHE_PARAMS);\n\t\t\t}\n\n\t\t\tthis.diskCacheFileCount = maxFileCount;\n\t\t\treturn this;\n\t\t}\n\n\t\t/** @deprecated Use {@link #diskCacheFileNameGenerator(com.nostra13.universalimageloader.cache.disc.naming.FileNameGenerator)} */\n\t\t@Deprecated\n\t\tpublic Builder discCacheFileNameGenerator(FileNameGenerator fileNameGenerator) {\n\t\t\treturn diskCacheFileNameGenerator(fileNameGenerator);\n\t\t}\n\n\t\t/**\n\t\t * Sets name generator for files cached in disk cache.<br />\n\t\t * Default value -","sourceCodeStart":433,"sourceCodeEnd":469,"githubUrl":"https://github.com/nostra13/Android-Universal-Image-Loader/blob/ba33ec64d0daaa881d35852460e78c58d086bc18/library/src/main/java/com/nostra13/universalimageloader/core/ImageLoaderConfiguration.java#L433-L469","documentation":"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.","triggerScenarios":"diskCacheFileCount(0) or negative; a count read from preferences/remote config that was never set and defaults to 0.","commonSituations":"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.","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)"],"exampleFix":"// before\nbuilder.diskCacheFileCount(prefs.getInt(\"cache_files\", 0)); // throws\n\n// after\nbuilder.diskCacheFileCount(Math.max(1, prefs.getInt(\"cache_files\", 200)));","handlingStrategy":"validation","validationCode":"int count = Math.max(1, configuredFileCount);\nbuilder.diskCacheFileCount(count);","typeGuard":"static boolean isValidFileCount(int n) {\n    return n > 0;\n}","tryCatchPattern":null,"preventionTips":["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"],"tags":["configuration","disk-cache","validation"],"backgroundTag":null,"analyzedSha":"ba33ec64d0daaa881d35852460e78c58d086bc18","analyzedAt":"2026-08-14T15:41:15.893Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}