{"record":{"id":"e62e33237f09732e","repo":"NativeScript/NativeScript","slug":"maxsize-0","errorCode":null,"errorMessage":"maxSize <= 0","messagePattern":"maxSize <= 0","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"packages/ui-mobile-base/android/widgets/src/main/java/org/nativescript/widgets/image/DiskLruCache.java","lineNumber":314,"sourceCode":"\t\tthis.journalFileTmp = new File(directory, JOURNAL_FILE_TMP);\n\t\tthis.valueCount = valueCount;\n\t\tthis.maxSize = maxSize;\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 appVersion\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 * @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)\n\t\tthrows IOException {\n\t\tif (maxSize <= 0) {\n\t\t\tthrow new IllegalArgumentException(\"maxSize <= 0\");\n\t\t}\n\t\tif (valueCount <= 0) {\n\t\t\tthrow new IllegalArgumentException(\"valueCount <= 0\");\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);\n\t\tif (cache.journalFile.exists()) {\n\t\t\ttry {\n\t\t\t\tcache.readJournal();\n\t\t\t\tcache.processJournal();\n\t\t\t\tcache.journalWriter = new BufferedWriter(new FileWriter(cache.journalFile, true),\n\t\t\t\t\tIO_BUFFER_SIZE);\n\t\t\t\treturn cache;\n\t\t\t} catch (IOException journalIsCorrupt) {\n//                System.logW(\"DiskLruCache \" + directory + \" is corrupt: \"\n//                        + journalIsCorrupt.getMessage() + \", removing\");\n\t\t\t\tcache.delete();","sourceCodeStart":296,"sourceCodeEnd":332,"githubUrl":"https://github.com/NativeScript/NativeScript/blob/6800aefa6511d23ddad8beb38ccc8541c5e91628/packages/ui-mobile-base/android/widgets/src/main/java/org/nativescript/widgets/image/DiskLruCache.java#L296-L332","documentation":"DiskLruCache.open() validates that maxSize (the byte budget for the disk cache) is strictly positive and throws IllegalArgumentException otherwise. A non-positive max size would make the cache immediately over-budget and eviction meaningless.","triggerScenarios":"Calling DiskLruCache.open(directory, appVersion, valueCount, maxSize) with maxSize <= 0 — typically 0 or a negative value from computed/misread configuration.","commonSituations":"Computing cache size from a config value that failed to parse (defaulting to 0), unit mistakes (bytes vs MB where the multiplier is missing), or unset settings.","solutions":["Pass a positive maxSize in bytes (e.g. 10 * 1024 * 1024 for 10MB)","Fix the size computation/config parsing that yielded 0 or negative","Add a pre-call clamp: Math.max(minCacheBytes, computedSize)"],"exampleFix":"// before\nDiskLruCache.open(dir, 1, 1, userConfigSize); // could be 0\n// after\nlong size = Math.max(5L * 1024 * 1024, userConfigSize);\nDiskLruCache.open(dir, 1, 1, size);","handlingStrategy":"validation","validationCode":"if (maxSize <= 0) {\n  maxSize = 10L * 1024 * 1024; // 10MB fallback\n}\nDiskLruCache.open(dir, appVersion, valueCount, maxSize);","typeGuard":"boolean isValidCacheSize(long maxSize) {\n  return maxSize > 0;\n}","tryCatchPattern":"try {\n  cache = DiskLruCache.open(dir, appVersion, valueCount, maxSize);\n} catch (IllegalArgumentException e) {\n  cache = DiskLruCache.open(dir, appVersion, valueCount, 10L * 1024 * 1024);\n}","preventionTips":["Verify size math (bytes vs MB) before passing maxSize","Guard against 0 defaults from failed config parsing","Clamp with Math.max(minBytes, configuredSize)"],"tags":["android","illegal-argument","disk-cache","configuration"],"backgroundTag":"invalid-argument-range","analyzedSha":"6800aefa6511d23ddad8beb38ccc8541c5e91628","analyzedAt":"2026-08-30T20:04:56.809Z","schemaVersion":2},"datasetVersion":"2026-08-30T23:17:21.991Z"}