CarGuo/GSYVideoPlayer · error · IllegalArgumentException

Max count must be positive number!

Error message

Max count must be positive number!

What it means

IllegalArgumentException thrown by the TotalCountLruDiskUsage constructor (TotalCountLruDiskUsage.java:14-18) when maxCount <= 0. TotalCountLruDiskUsage is the LRU trimming strategy that caps the cache by file count; it is created internally by HttpProxyCacheServer.Builder.maxCacheCount(int) (HttpProxyCacheServer.java:415). The check is fail-fast configuration validation: a non-positive count makes an LRU count limit meaningless, so the library refuses to construct the server rather than misbehave later.

Source

Thrown at gsyVideoPlayer-proxy_cache/src/main/java/com/danikula/videocache/file/TotalCountLruDiskUsage.java:16

package com.danikula.videocache.file;

import java.io.File;

/**
 * {@link DiskUsage} that uses LRU (Least Recently Used) strategy and trims cache size to max files count if needed.
 *
 * @author Alexey Danilov (danikula@gmail.com).
 */
public class TotalCountLruDiskUsage extends LruDiskUsage {

    private final int maxCount;

    public TotalCountLruDiskUsage(int maxCount) {
        if (maxCount <= 0) {
            throw new IllegalArgumentException("Max count must be positive number!");
        }
        this.maxCount = maxCount;
    }

    @Override
    protected boolean accept(File file, long totalSize, int totalCount) {
        return totalCount <= maxCount;
    }
}

View on GitHub (pinned to e5d74d3aa9)

Solutions

  1. Pass a positive count to maxCacheCount(), e.g. maxCacheCount(50).
  2. If 'unlimited' was intended, do not call maxCacheCount at all — the Builder defaults to TotalSizeLruDiskUsage(DEFAULT_MAX_SIZE) (HttpProxyCacheServer.java:357).
  3. Clamp externally sourced values before use: int effective = Math.max(1, configValue); builder.maxCacheCount(effective).
  4. If the count comes from a computation, check the divisor/units (per-file size assumption too large yields 0 on small-storage devices).

Example fix

// before
HttpProxyCacheServer server = new HttpProxyCacheServer.Builder(context)
        .maxCacheCount(remoteConfigCacheCount) // 0 until backend responds -> IllegalArgumentException
        .build();

// after
int cacheCount = Math.max(1, remoteConfigCacheCount); // sane floor
HttpProxyCacheServer server = new HttpProxyCacheServer.Builder(context)
        .maxCacheCount(cacheCount)
        .build();
Defensive patterns

Strategy: validation

Validate before calling

// Validate before calling maxCacheCount()
int requestedCount = config.getVideoCacheFileCount(); // any external source
if (requestedCount <= 0) {
    throw new IllegalStateException("video cache maxCacheCount must be > 0, got " + requestedCount);
}
HttpProxyCacheServer server = new HttpProxyCacheServer.Builder(context)
        .maxCacheCount(requestedCount)
        .build();

Try / catch

try {
    server = builder.maxCacheCount(count).build();
} catch (IllegalArgumentException e) {
    if ("Max count must be positive number!".equals(e.getMessage())) {
        server = builder.build(); // fall back to builder defaults
    } else {
        throw e;
    }
}

Prevention

When it happens

Trigger: Calling new HttpProxyCacheServer.Builder(context).maxCacheCount(0) or any negative value, then .build() — build() constructs new TotalCountLruDiskUsage(count) at HttpProxyCacheServer.java:415 and the constructor throws. Also instantiating TotalCountLruDiskUsage directly with 0/negative, e.g. from a computed value such as available-storage-derived count, a remote-config parameter defaulting to 0, or an unset constant.

Common situations: Cache size/count pulled from remote config or a BuildConfig field that defaults to 0 until the backend responds; a count computed as deviceStorageMB / someUnit that underflows to 0 on small devices; copy-paste of maxCacheCount(0) intending 'unlimited' (0 does NOT mean unlimited — omit the call to use the default 512 MB TotalSizeLruDiskUsage); unit tests constructing the strategy with edge-case values.

Related errors


AI-assisted analysis of CarGuo/GSYVideoPlayer@e5d74d3aa9 (2026-08-14). Data as JSON: /api/errors/0fe1b1f7f1efb683. Report an issue: GitHub.