{"record":{"id":"4b7e8011277a4b88","repo":"nostra13/Android-Universal-Image-Loader","slug":"filenamegenerator-argument-must-be-not-null-4b7e80","errorCode":null,"errorMessage":"fileNameGenerator argument must be not null","messagePattern":"fileNameGenerator argument must be not null","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"library/src/main/java/com/nostra13/universalimageloader/cache/disc/impl/ext/LruDiskCache.java","lineNumber":94,"sourceCode":"\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)\n\t\t\tthrows IOException {\n\t\ttry {\n\t\t\tcache = DiskLruCache.open(cacheDir, 1, 1, cacheMaxSize, cacheMaxFileCount);","sourceCodeStart":76,"sourceCodeEnd":112,"githubUrl":"https://github.com/nostra13/Android-Universal-Image-Loader/blob/ba33ec64d0daaa881d35852460e78c58d086bc18/library/src/main/java/com/nostra13/universalimageloader/cache/disc/impl/ext/LruDiskCache.java#L76-L112","documentation":"LruDiskCache's constructor throws IllegalArgumentException when fileNameGenerator is null. The generator's output becomes the DiskLruCache key and must match [a-z0-9_-]{1,64}; the cache cannot name files without it, so construction fails fast. LruDiskCache.initDiskCache passes generator output straight into DiskLruCache, which independently enforces the key regex.","triggerScenarios":"Calling new LruDiskCache(cacheDir, reserve, null, maxSize, maxFileCount). Higher-level UIL flows supply DefaultConfigurationFactory.createFileNameGenerator() automatically, so this occurs in custom construction code or broken DI wiring.","commonSituations":"Hand-rolled LruDiskCache setup that omits the generator argument handling; DI containers missing a FileNameGenerator binding; refactors that null out the generator 'temporarily'.","solutions":["Pass a generator: new HashCodeFileNameGenerator() or new Md5FileNameGenerator().","Or use ImageLoaderConfiguration.builder(context).diskCache(new LruDiskCache(dir, reserve, new HashCodeFileNameGenerator(), size, 0)) with an explicit, non-null generator.","Add a DI guard/requireNonNull on the generator binding so failures surface at wiring time."],"exampleFix":"// before\nnew LruDiskCache(dir, null, null, 50 * 1024 * 1024, 0);\n\n// after\nnew LruDiskCache(dir, null, new HashCodeFileNameGenerator(), 50 * 1024 * 1024, 0);","handlingStrategy":"validation","validationCode":"FileNameGenerator gen = Objects.requireNonNull(generator, \"fileNameGenerator\");\nnew LruDiskCache(dir, reserve, gen, 50L * 1024 * 1024, 0);","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Default to new HashCodeFileNameGenerator() when in doubt.","Make the generator a required (non-optional) dependency in DI wiring.","The generator's output must also satisfy [a-z0-9_-]{1,64} — use a hashing generator to be safe."],"tags":["disk-cache","lru","validation","constructor","null-check","file-naming"],"backgroundTag":null,"analyzedSha":"ba33ec64d0daaa881d35852460e78c58d086bc18","analyzedAt":"2026-08-14T15:41:15.893Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}