{"record":{"id":"0b294ad00351a239","repo":"nostra13/Android-Universal-Image-Loader","slug":"valuecount-0","errorCode":null,"errorMessage":"valueCount <= 0","messagePattern":"valueCount <= 0","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"library/src/main/java/com/nostra13/universalimageloader/cache/disc/impl/ext/DiskLruCache.java","lineNumber":212,"sourceCode":"\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.\n\t\tDiskLruCache cache = new DiskLruCache(directory, appVersion, valueCount, maxSize, maxFileCount);\n\t\tif (cache.journalFile.exists()) {\n\t\t\ttry {","sourceCodeStart":194,"sourceCodeEnd":230,"githubUrl":"https://github.com/nostra13/Android-Universal-Image-Loader/blob/ba33ec64d0daaa881d35852460e78c58d086bc18/library/src/main/java/com/nostra13/universalimageloader/cache/disc/impl/ext/DiskLruCache.java#L194-L230","documentation":"DiskLruCache.open() throws IllegalArgumentException when valueCount is zero or negative. valueCount defines how many files each cache entry owns (keys map to valueCount files named key.0..key.N-1); at least one value per entry is required. The library itself always calls open() with valueCount = 1.","triggerScenarios":"Calling DiskLruCache.open(directory, appVersion, 0, maxSize, maxFileCount) or with a negative valueCount. In this codebase the only production call site (LruDiskCache.initDiskCache) passes 1, so hitting it means custom code called open() directly with a computed or hardcoded 0.","commonSituations":"Copy-pasting an open() call and zeroing parameters you don't understand; deriving valueCount from a multi-file entry scheme that computed 0 entries; adapting an older sample that omitted the parameter.","solutions":["Pass 1 for valueCount unless you deliberately implement multi-file entries.","Audit custom DiskLruCache wrappers for hardcoded zeros in the open() call.","Prefer LruDiskCache, which always uses valueCount = 1 internally."],"exampleFix":"// before\nDiskLruCache.open(dir, appVersion, 0, maxSize, maxFileCount);\n\n// after\nDiskLruCache.open(dir, appVersion, 1, maxSize, maxFileCount);","handlingStrategy":"validation","validationCode":"if (valueCount <= 0) throw new IllegalArgumentException(\"valueCount must be >= 1, got \" + valueCount);\nDiskLruCache.open(dir, appVersion, valueCount, maxSize, maxFileCount);","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Hardcode valueCount = 1 unless you implement multi-file entries deliberately.","Don't zero out parameters you don't understand when copy-pasting open() calls.","Let LruDiskCache manage open() — it always passes 1."],"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"}