{"record":{"id":"0465ab051590c782","repo":"nostra13/Android-Universal-Image-Loader","slug":"availablememorypercent-must-be-in-range-0-1","errorCode":null,"errorMessage":"availableMemoryPercent must be in range (0 < % < 100)","messagePattern":"availableMemoryPercent must be in range \\(0 < % < 100\\)","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"library/src/main/java/com/nostra13/universalimageloader/core/ImageLoaderConfiguration.java","lineNumber":380,"sourceCode":"\t\t\t\tL.w(WARNING_OVERLAP_MEMORY_CACHE);\n\t\t\t}\n\n\t\t\tthis.memoryCacheSize = memoryCacheSize;\n\t\t\treturn this;\n\t\t}\n\n\t\t/**\n\t\t * Sets maximum memory cache size (in percent of available app memory) for {@link android.graphics.Bitmap\n\t\t * bitmaps}.<br />\n\t\t * Default value - 1/8 of available app memory.<br />\n\t\t * <b>NOTE:</b> If you use this method then\n\t\t * {@link com.nostra13.universalimageloader.cache.memory.impl.LruMemoryCache LruMemoryCache} will be used as\n\t\t * memory cache. You can use {@link #memoryCache(MemoryCache)} method to set your own implementation of\n\t\t * {@link MemoryCache}.\n\t\t */\n\t\tpublic Builder memoryCacheSizePercentage(int availableMemoryPercent) {\n\t\t\tif (availableMemoryPercent <= 0 || availableMemoryPercent >= 100) {\n\t\t\t\tthrow new IllegalArgumentException(\"availableMemoryPercent must be in range (0 < % < 100)\");\n\t\t\t}\n\n\t\t\tif (memoryCache != null) {\n\t\t\t\tL.w(WARNING_OVERLAP_MEMORY_CACHE);\n\t\t\t}\n\n\t\t\tlong availableMemory = Runtime.getRuntime().maxMemory();\n\t\t\tmemoryCacheSize = (int) (availableMemory * (availableMemoryPercent / 100f));\n\t\t\treturn this;\n\t\t}\n\n\t\t/**\n\t\t * Sets memory cache for {@link android.graphics.Bitmap bitmaps}.<br />\n\t\t * Default value - {@link com.nostra13.universalimageloader.cache.memory.impl.LruMemoryCache LruMemoryCache}\n\t\t * with limited memory cache size (size = 1/8 of available app memory)<br />\n\t\t * <br />\n\t\t * <b>NOTE:</b> If you set custom memory cache then following configuration option will not be considered:\n\t\t * <ul>","sourceCodeStart":362,"sourceCodeEnd":398,"githubUrl":"https://github.com/nostra13/Android-Universal-Image-Loader/blob/ba33ec64d0daaa881d35852460e78c58d086bc18/library/src/main/java/com/nostra13/universalimageloader/core/ImageLoaderConfiguration.java#L362-L398","documentation":"ImageLoaderConfiguration.Builder.memoryCacheSizePercentage(int) accepts only values strictly between 0 and 100 (exclusive on both ends), throwing IllegalArgumentException otherwise. The percentage is applied to Runtime.getRuntime().maxMemory() to derive the byte budget; 0 would disable the cache and 100 would try to use the entire heap, both misconfigurations. The result is stored in memoryCacheSize and LruMemoryCache is used.","triggerScenarios":"memoryCacheSizePercentage(0), (100), or (negative); passing a fraction like 0.25 (25 percent already divided by 100) instead of the integer 25.","commonSituations":"Confusing the API with fractional-style libraries and passing 0.25 -> truncates to 0; UI slider allowing endpoint values 0 or 100; remote-config percentage delivered as 100 for 'max'.","solutions":["Pass an integer percent strictly inside (0,100): memoryCacheSizePercentage(25)","Clamp user/remote input: Math.min(99, Math.max(1, pct))","If you need exact bytes, use memoryCacheSize(bytes) instead"],"exampleFix":"// before\nbuilder.memoryCacheSizePercentage((int) (0.25f * 100)); // fine, but common bug:\nbuilder.memoryCacheSizePercentage(0); // or 100 -> throws\n\n// after\nbuilder.memoryCacheSizePercentage(25); // 25% of available memory\n// clamped remote value:\nbuilder.memoryCacheSizePercentage(Math.min(99, Math.max(1, remotePct)));","handlingStrategy":"validation","validationCode":"int pct = Math.min(99, Math.max(1, requestedPercent));\nbuilder.memoryCacheSizePercentage(pct);","typeGuard":"static boolean isValidMemoryPercent(int pct) {\n    return pct > 0 && pct < 100;\n}","tryCatchPattern":null,"preventionTips":["Pass an integer percent (e.g. 25), not a fraction (0.25)","Clamp user-facing or remote-config percentages to [1, 99]","Use memoryCacheSize(bytes) when you need exact control"],"tags":["configuration","memory-cache","validation","percentage"],"backgroundTag":null,"analyzedSha":"ba33ec64d0daaa881d35852460e78c58d086bc18","analyzedAt":"2026-08-14T15:41:15.893Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}