{"record":{"id":"b3619bd92e69dc86","repo":"nostra13/Android-Universal-Image-Loader","slug":"cachemaxfilecount-argument-must-be-positive-number","errorCode":null,"errorMessage":"cacheMaxFileCount argument must be positive number","messagePattern":"cacheMaxFileCount argument must be positive number","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"library/src/main/java/com/nostra13/universalimageloader/cache/disc/impl/ext/LruDiskCache.java","lineNumber":91,"sourceCode":"\t * @param cacheDir          Directory for file caching\n\t * @param reserveCacheDir   null-ok; Reserve directory for file caching. It's used when the primary directory isn't available.\n\t * @param fileNameGenerator {@linkplain com.nostra13.universalimageloader.cache.disc.naming.FileNameGenerator\n\t *                          Name generator} for cached files. Generated names must match the regex\n\t *                          <strong>[a-z0-9_-]{1,64}</strong>\n\t * @param cacheMaxSize      Max cache size in bytes. <b>0</b> means cache size is unlimited.\n\t * @param cacheMaxFileCount Max file count in cache. <b>0</b> means file count is unlimited.\n\t * @throws IOException if cache can't be initialized (e.g. \"No space left on device\")\n\t */\n\tpublic LruDiskCache(File cacheDir, File reserveCacheDir, FileNameGenerator fileNameGenerator, long cacheMaxSize,\n\t\t\tint cacheMaxFileCount) throws IOException {\n\t\tif (cacheDir == null) {\n\t\t\tthrow new IllegalArgumentException(\"cacheDir\" + ERROR_ARG_NULL);\n\t\t}\n\t\tif (cacheMaxSize < 0) {\n\t\t\tthrow new IllegalArgumentException(\"cacheMaxSize\" + ERROR_ARG_NEGATIVE);\n\t\t}\n\t\tif (cacheMaxFileCount < 0) {\n\t\t\tthrow new IllegalArgumentException(\"cacheMaxFileCount\" + ERROR_ARG_NEGATIVE);\n\t\t}\n\t\tif (fileNameGenerator == null) {\n\t\t\tthrow new IllegalArgumentException(\"fileNameGenerator\" + ERROR_ARG_NULL);\n\t\t}\n\n\t\tif (cacheMaxSize == 0) {\n\t\t\tcacheMaxSize = Long.MAX_VALUE;\n\t\t}\n\t\tif (cacheMaxFileCount == 0) {\n\t\t\tcacheMaxFileCount = Integer.MAX_VALUE;\n\t\t}\n\n\t\tthis.reserveCacheDir = reserveCacheDir;\n\t\tthis.fileNameGenerator = fileNameGenerator;\n\t\tinitCache(cacheDir, reserveCacheDir, cacheMaxSize, cacheMaxFileCount);\n\t}\n\n\tprivate void initCache(File cacheDir, File reserveCacheDir, long cacheMaxSize, int cacheMaxFileCount)","sourceCodeStart":73,"sourceCodeEnd":109,"githubUrl":"https://github.com/nostra13/Android-Universal-Image-Loader/blob/ba33ec64d0daaa881d35852460e78c58d086bc18/library/src/main/java/com/nostra13/universalimageloader/cache/disc/impl/ext/LruDiskCache.java#L73-L109","documentation":"LruDiskCache's constructor throws IllegalArgumentException when cacheMaxFileCount is negative. As with cacheMaxSize, 0 is the documented 'unlimited' value (normalized to Integer.MAX_VALUE) and any negative count is rejected. The message wording ('must be positive number') is slightly off since 0 is legal.","triggerScenarios":"Calling new LruDiskCache(cacheDir, reserve, generator, maxSize, -1) or any negative count, e.g. from .diskCacheFileCount(-1) style configuration or a count computed as (limit - current) that underflowed.","commonSituations":"Using -1 as an 'unset' default in config objects and forwarding it directly; unit tests passing sentinel values; refactors that changed the parameter's type/order.","solutions":["Pass a positive count (e.g. 10000) or 0 for unlimited.","Clamp computed counts with Math.max(0, n).","Map sentinel values (-1) to 0 before construction."],"exampleFix":"// before\nint count = quota - usedFiles; // negative when over quota\nnew LruDiskCache(dir, null, gen, maxSize, count);\n\n// after\nint count = Math.max(0, quota - usedFiles);\nnew LruDiskCache(dir, null, gen, maxSize, count);","handlingStrategy":"validation","validationCode":"int countArg = (cacheMaxFileCount >= 0) ? cacheMaxFileCount : 0; // 0 == unlimited\nnew LruDiskCache(dir, reserve, gen, maxSize, countArg);","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Clamp count computations with Math.max(0, n).","Don't forward -1 sentinel defaults from config objects into the constructor.","0 means unlimited; pick a positive number like 10000 for a bounded file count."],"tags":["disk-cache","lru","validation","configuration","constructor"],"backgroundTag":null,"analyzedSha":"ba33ec64d0daaa881d35852460e78c58d086bc18","analyzedAt":"2026-08-14T15:41:15.893Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}