NativeScript/NativeScript · error · IllegalArgumentException

maxSize <= 0

Error message

maxSize <= 0

What it means

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.

Source

Thrown at packages/ui-mobile-base/android/widgets/src/main/java/org/nativescript/widgets/image/DiskLruCache.java:314

		this.journalFileTmp = new File(directory, JOURNAL_FILE_TMP);
		this.valueCount = valueCount;
		this.maxSize = maxSize;
	}

	/**
	 * Opens the cache in {@code directory}, creating a cache if none exists
	 * there.
	 *
	 * @param directory  a writable directory
	 * @param appVersion
	 * @param valueCount the number of values per cache entry. Must be positive.
	 * @param maxSize    the maximum number of bytes this cache should use to store
	 * @throws IOException if reading or writing the cache directory fails
	 */
	public static DiskLruCache open(File directory, int appVersion, int valueCount, long maxSize)
		throws IOException {
		if (maxSize <= 0) {
			throw new IllegalArgumentException("maxSize <= 0");
		}
		if (valueCount <= 0) {
			throw new IllegalArgumentException("valueCount <= 0");
		}

		// prefer to pick up where we left off
		DiskLruCache cache = new DiskLruCache(directory, appVersion, valueCount, maxSize);
		if (cache.journalFile.exists()) {
			try {
				cache.readJournal();
				cache.processJournal();
				cache.journalWriter = new BufferedWriter(new FileWriter(cache.journalFile, true),
					IO_BUFFER_SIZE);
				return cache;
			} catch (IOException journalIsCorrupt) {
//                System.logW("DiskLruCache " + directory + " is corrupt: "
//                        + journalIsCorrupt.getMessage() + ", removing");
				cache.delete();

View on GitHub (pinned to 6800aefa65)

Solutions

  1. Pass a positive maxSize in bytes (e.g. 10 * 1024 * 1024 for 10MB)
  2. Fix the size computation/config parsing that yielded 0 or negative
  3. Add a pre-call clamp: Math.max(minCacheBytes, computedSize)

Example fix

// before
DiskLruCache.open(dir, 1, 1, userConfigSize); // could be 0
// after
long size = Math.max(5L * 1024 * 1024, userConfigSize);
DiskLruCache.open(dir, 1, 1, size);
Defensive patterns

Strategy: validation

Validate before calling

if (maxSize <= 0) {
  maxSize = 10L * 1024 * 1024; // 10MB fallback
}
DiskLruCache.open(dir, appVersion, valueCount, maxSize);

Type guard

boolean isValidCacheSize(long maxSize) {
  return maxSize > 0;
}

Try / catch

try {
  cache = DiskLruCache.open(dir, appVersion, valueCount, maxSize);
} catch (IllegalArgumentException e) {
  cache = DiskLruCache.open(dir, appVersion, valueCount, 10L * 1024 * 1024);
}

Prevention

When it happens

Trigger: Calling DiskLruCache.open(directory, appVersion, valueCount, maxSize) with maxSize <= 0 — typically 0 or a negative value from computed/misread configuration.

Common situations: 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.

Related errors


AI-assisted analysis of NativeScript/NativeScript@6800aefa65 (2026-08-30). Data as JSON: /api/errors/e62e33237f09732e. Report an issue: GitHub.