{"record":{"id":"7c6ee98db8ea350b","repo":"nostra13/Android-Universal-Image-Loader","slug":"maxcachesize-must-be-a-positive-number","errorCode":null,"errorMessage":"maxCacheSize must be a positive number","messagePattern":"maxCacheSize 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":426,"sourceCode":"\t\t\treturn this;\n\t\t}\n\n\t\t/** @deprecated Use {@link #diskCacheSize(int)} instead */\n\t\t@Deprecated\n\t\tpublic Builder discCacheSize(int maxCacheSize) {\n\t\t\treturn diskCacheSize(maxCacheSize);\n\t\t}\n\n\t\t/**\n\t\t * Sets maximum disk cache size for images (in bytes).<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 diskCacheSize(int maxCacheSize) {\n\t\t\tif (maxCacheSize <= 0) throw new IllegalArgumentException(\"maxCacheSize 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.diskCacheSize = maxCacheSize;\n\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 />","sourceCodeStart":408,"sourceCodeEnd":444,"githubUrl":"https://github.com/nostra13/Android-Universal-Image-Loader/blob/ba33ec64d0daaa881d35852460e78c58d086bc18/library/src/main/java/com/nostra13/universalimageloader/core/ImageLoaderConfiguration.java#L408-L444","documentation":"ImageLoaderConfiguration.Builder.diskCacheSize(int) validates that the LruDiskCache byte cap is strictly positive; a zero or negative cap would make the disk LRU immediately evict everything. Setting this switches the disk cache implementation to LruDiskCache and logs a warning (WARNING_OVERLAP_DISK_CACHE_PARAMS) if you had already set a custom diskCache().","triggerScenarios":"diskCacheSize(0) or negative; size computed from a config/free-space expression that returns 0 when storage is low; passing a megabyte count without the 1024*1024 multiplier during experiments.","commonSituations":"StatFs-based free-space calculations returning 0 on devices reporting unusual block sizes; A/B-flag-gated cache sizes where one branch is 0 ('cache disabled') instead of using no disk cache; remote config defaulting to 0.","solutions":["Pass explicit positive bytes: diskCacheSize(50 * 1024 * 1024)","To disable the disk cache, don't call diskCacheSize at all / don't configure a disk cache, rather than passing 0","Clamp dynamic values: Math.max(1, computedBytes)"],"exampleFix":"// before\nlong free = new StatFs(dir.getPath()).getAvailableBytes();\nbuilder.diskCacheSize((int) (free * 0.1)); // 0 when free space misreported\n\n// after\nint bytes = (int) Math.max(10L * 1024 * 1024, free / 10);\nbuilder.diskCacheSize(bytes);","handlingStrategy":"validation","validationCode":"int bytes = Math.max(1, computedDiskCacheBytes);\nbuilder.diskCacheSize(bytes);","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Do not use 0 to mean 'no disk cache' — omit the disk cache config instead","Clamp free-space-derived sizes to a sane floor (e.g. 10 MB)","Express disk sizes in bytes with explicit 1024*1024 factors"],"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"}