{"record":{"id":"0e4e354ec79e9e44","repo":"nostra13/Android-Universal-Image-Loader","slug":"maxsize-0","errorCode":null,"errorMessage":"maxSize <= 0","messagePattern":"maxSize <= 0","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"library/src/main/java/com/nostra13/universalimageloader/cache/disc/impl/ext/DiskLruCache.java","lineNumber":206,"sourceCode":"\t\tthis.valueCount = valueCount;\n\t\tthis.maxSize = maxSize;\n\t\tthis.maxFileCount = maxFileCount;\n\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}","sourceCodeStart":188,"sourceCodeEnd":224,"githubUrl":"https://github.com/nostra13/Android-Universal-Image-Loader/blob/ba33ec64d0daaa881d35852460e78c58d086bc18/library/src/main/java/com/nostra13/universalimageloader/cache/disc/impl/ext/DiskLruCache.java#L188-L224","documentation":"DiskLruCache.open() throws IllegalArgumentException when maxSize is zero or negative. maxSize caps the total bytes the cache may store, so a non-positive cap is meaningless. LruDiskCache avoids this by mapping its '0 = unlimited' convention to Long.MAX_VALUE before calling open().","triggerScenarios":"Calling DiskLruCache.open(directory, appVersion, valueCount, 0, maxFileCount) or with a negative maxSize. Also reachable indirectly if a wrapper passes an unnormalized 0 where 0 was intended to mean 'unlimited'.","commonSituations":"Treating 0 as 'unlimited' when using the ext DiskLruCache directly (that convention belongs to LruDiskCache/DiskCacheConfig, not to open()); computing maxSize from a config value or disk-free-space query that came back 0 or -1; arithmetic that subtracts a reserve from available space and underflows.","solutions":["Pass a strictly positive byte limit, e.g. 50 * 1024 * 1024.","If you want an unlimited cache, pass Long.MAX_VALUE (this is exactly what LruDiskCache does for cacheMaxSize == 0).","Prefer the higher-level LruDiskCache or ImageLoaderConfiguration.diskCacheSize(...) which normalize 0 to unlimited for you."],"exampleFix":"// before\nDiskLruCache.open(dir, appVersion, 1, 0, 10000); // IllegalArgumentException\n\n// after\nDiskLruCache.open(dir, appVersion, 1, Long.MAX_VALUE, 10000);","handlingStrategy":"validation","validationCode":"long effectiveMax = (maxSize > 0) ? maxSize : Long.MAX_VALUE; // normalize 0/unset -> unlimited\nDiskLruCache.open(dir, appVersion, valueCount, effectiveMax, maxFileCount);","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Remember '0 = unlimited' is a LruDiskCache convention, not a DiskLruCache.open() one.","Clamp any computed size with Math.max(1, size) before calling open().","Prefer ImageLoaderConfiguration builder APIs (diskCacheSize) which normalize values for you."],"tags":["disk-cache","lru","validation","configuration","constructor"],"backgroundTag":null,"analyzedSha":"ba33ec64d0daaa881d35852460e78c58d086bc18","analyzedAt":"2026-08-14T15:41:15.893Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}