{"record":{"id":"7e584385ba16ee50","repo":"bilibili/DanmakuFlameMaster","slug":"the-pool-limit-must-be-0","errorCode":null,"errorMessage":"The pool limit must be > 0","messagePattern":"The pool limit must be > 0","errorType":"exception","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"DanmakuFlameMaster/src/main/java/master/flame/danmaku/danmaku/model/objectpool/FinitePool.java","lineNumber":43,"sourceCode":"\n    /** If true, mLimit is ignored */\n    private final boolean mInfinite;\n\n    /** Next object to acquire */\n    private T mRoot;\n\n    /** Number of objects in the pool */\n    private int mPoolCount;\n\n    FinitePool(PoolableManager<T> manager) {\n        mManager = manager;\n        mLimit = 0;\n        mInfinite = true;\n    }\n\n    FinitePool(PoolableManager<T> manager, int limit) {\n        if (limit <= 0) {\n            throw new IllegalArgumentException(\"The pool limit must be > 0\");\n        }\n\n        mManager = manager;\n        mLimit = limit;\n        mInfinite = false;\n    }\n\n    public T acquire() {\n        T element;\n\n        if (mRoot != null) {\n            element = mRoot;\n            mRoot = element.getNextPoolable();\n            mPoolCount--;\n        } else {\n            element = mManager.newInstance();\n        }\n","sourceCodeStart":25,"sourceCodeEnd":61,"githubUrl":"https://github.com/bilibili/DanmakuFlameMaster/blob/e2846461a09e33720a049f628f09c653f55531f0/DanmakuFlameMaster/src/main/java/master/flame/danmaku/danmaku/model/objectpool/FinitePool.java#L25-L61","documentation":"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.","triggerScenarios":"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).","commonSituations":"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.","solutions":["Pass a positive limit, e.g. new FinitePool(manager, 64).","Audit where the limit value comes from and clamp it: Math.max(1, configuredLimit).","If unbounded pooling is acceptable, use the single-argument FinitePool(manager) constructor instead."],"exampleFix":"// before\nFinitePool<Danmaku> pool = new FinitePool<>(manager, config.poolSize); // poolSize == 0\n// after\nint limit = Math.max(1, config.poolSize);\nFinitePool<Danmaku> pool = new FinitePool<>(manager, limit);","handlingStrategy":"validation","validationCode":"int limit = Math.max(1, configuredPoolSize);\nif (limit <= 0) { throw new IllegalStateException(\"pool size must be > 0, got \" + configuredPoolSize); }","typeGuard":"boolean isValidLimit = (configuredPoolSize > 0);","tryCatchPattern":"try {\n    pool = new FinitePool<>(manager, limit);\n} catch (IllegalArgumentException e) {\n    pool = new FinitePool<>(manager, DEFAULT_POOL_LIMIT);\n}","preventionTips":["Clamp configured pool sizes to at least 1 before constructing pools.","Use the single-argument FinitePool(manager) constructor when no bound is needed.","Trace the limit's source (config/setting/arithmetic) and validate at the boundary."],"tags":["objectpool","danmaku","invalid-argument","configuration"],"backgroundTag":"invalid-argument-value","analyzedSha":"e2846461a09e33720a049f628f09c653f55531f0","analyzedAt":"2026-09-10T14:31:54.917Z","contentChangedAt":"2026-09-10T14:31:54.917Z","schemaVersion":2},"datasetVersion":"2026-09-15T23:17:13.987Z"}