bilibili/DanmakuFlameMaster · error · IllegalArgumentException

The pool limit must be > 0

Error message

The pool limit must be > 0

What it means

FinitePool's bounded constructor requires a positive limit because it caps how many objects the pool may hold. Passing a limit of 0 or negative is a configuration error and is rejected with IllegalArgumentException.

Solutions

  1. Pass a positive limit, e.g. new FinitePool(manager, 64).
  2. Audit where the limit value comes from and clamp it: Math.max(1, configuredLimit).
  3. If unbounded pooling is acceptable, use the single-argument FinitePool(manager) constructor instead.

Example fix

// before
FinitePool<Danmaku> pool = new FinitePool<>(manager, config.poolSize); // poolSize == 0
// after
int limit = Math.max(1, config.poolSize);
FinitePool<Danmaku> pool = new FinitePool<>(manager, limit);
Defensive patterns

Strategy: validation

Validate before calling

int limit = Math.max(1, configuredPoolSize);
if (limit <= 0) { throw new IllegalStateException("pool size must be > 0, got " + configuredPoolSize); }

Type guard

boolean isValidLimit = (configuredPoolSize > 0);

Try / catch

try {
    pool = new FinitePool<>(manager, limit);
} catch (IllegalArgumentException e) {
    pool = new FinitePool<>(manager, DEFAULT_POOL_LIMIT);
}

Prevention

When it happens

Trigger: Calling new FinitePool(manager, 0) or new FinitePool(manager, -1), or a factory/config path that computes the pool size as 0 (e.g. dividing counts or reading an unset config value).

Common situations: Configuring a danmaku object pool size from a constant or user setting that was 0; arithmetic on pool capacity producing a non-positive value; copy-paste of pool code with a placeholder limit.

Understand the failure class

Background: "Must be a positive integer", "Invalid value", "Unsupported": the invalid-argument-value error family, when a library rejects the value you pass — this error's family across 35 libraries.

Related errors


AI-assisted analysis of bilibili/DanmakuFlameMaster@e2846461a0 (2026-09-10). Data as JSON: /api/errors/7e584385ba16ee50. Report an issue: GitHub.

Appendix: source

Thrown at DanmakuFlameMaster/src/main/java/master/flame/danmaku/danmaku/model/objectpool/FinitePool.java:43

    /** If true, mLimit is ignored */
    private final boolean mInfinite;

    /** Next object to acquire */
    private T mRoot;

    /** Number of objects in the pool */
    private int mPoolCount;

    FinitePool(PoolableManager<T> manager) {
        mManager = manager;
        mLimit = 0;
        mInfinite = true;
    }

    FinitePool(PoolableManager<T> manager, int limit) {
        if (limit <= 0) {
            throw new IllegalArgumentException("The pool limit must be > 0");
        }

        mManager = manager;
        mLimit = limit;
        mInfinite = false;
    }

    public T acquire() {
        T element;

        if (mRoot != null) {
            element = mRoot;
            mRoot = element.getNextPoolable();
            mPoolCount--;
        } else {
            element = mManager.newInstance();
        }

View on GitHub (pinned to e2846461a0)