{"record":{"id":"0fe1b1f7f1efb683","repo":"CarGuo/GSYVideoPlayer","slug":"max-count-must-be-positive-number","errorCode":null,"errorMessage":"Max count must be positive number!","messagePattern":"Max count must be positive number!","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"gsyVideoPlayer-proxy_cache/src/main/java/com/danikula/videocache/file/TotalCountLruDiskUsage.java","lineNumber":16,"sourceCode":"package com.danikula.videocache.file;\n\nimport java.io.File;\n\n/**\n * {@link DiskUsage} that uses LRU (Least Recently Used) strategy and trims cache size to max files count if needed.\n *\n * @author Alexey Danilov (danikula@gmail.com).\n */\npublic class TotalCountLruDiskUsage extends LruDiskUsage {\n\n    private final int maxCount;\n\n    public TotalCountLruDiskUsage(int maxCount) {\n        if (maxCount <= 0) {\n            throw new IllegalArgumentException(\"Max count must be positive number!\");\n        }\n        this.maxCount = maxCount;\n    }\n\n    @Override\n    protected boolean accept(File file, long totalSize, int totalCount) {\n        return totalCount <= maxCount;\n    }\n}\n","sourceCodeStart":1,"sourceCodeEnd":26,"githubUrl":"https://github.com/CarGuo/GSYVideoPlayer/blob/e5d74d3aa9d7fb1393a879e33ee380f8f41354f1/gsyVideoPlayer-proxy_cache/src/main/java/com/danikula/videocache/file/TotalCountLruDiskUsage.java#L1-L26","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Pass a positive count to maxCacheCount(), e.g. maxCacheCount(50).","If 'unlimited' was intended, do not call maxCacheCount at all — the Builder defaults to TotalSizeLruDiskUsage(DEFAULT_MAX_SIZE) (HttpProxyCacheServer.java:357).","Clamp externally sourced values before use: int effective = Math.max(1, configValue); builder.maxCacheCount(effective).","If the count comes from a computation, check the divisor/units (per-file size assumption too large yields 0 on small-storage devices)."],"exampleFix":"// before\nHttpProxyCacheServer server = new HttpProxyCacheServer.Builder(context)\n        .maxCacheCount(remoteConfigCacheCount) // 0 until backend responds -> IllegalArgumentException\n        .build();\n\n// after\nint cacheCount = Math.max(1, remoteConfigCacheCount); // sane floor\nHttpProxyCacheServer server = new HttpProxyCacheServer.Builder(context)\n        .maxCacheCount(cacheCount)\n        .build();","handlingStrategy":"validation","validationCode":"// Validate before calling maxCacheCount()\nint requestedCount = config.getVideoCacheFileCount(); // any external source\nif (requestedCount <= 0) {\n    throw new IllegalStateException(\"video cache maxCacheCount must be > 0, got \" + requestedCount);\n}\nHttpProxyCacheServer server = new HttpProxyCacheServer.Builder(context)\n        .maxCacheCount(requestedCount)\n        .build();","typeGuard":null,"tryCatchPattern":"try {\n    server = builder.maxCacheCount(count).build();\n} catch (IllegalArgumentException e) {\n    if (\"Max count must be positive number!\".equals(e.getMessage())) {\n        server = builder.build(); // fall back to builder defaults\n    } else {\n        throw e;\n    }\n}","preventionTips":["Treat maxCacheCount as a required positive value in config schema validation (fail at config load, not at player start).","Clamp remote-config/computed values: Math.max(1, value).","Remember 0 does not mean unlimited — omit the call for the default size-based limit.","Cover maxCacheCount edge cases (0, 1, negative) in unit tests for your proxy-cache setup code."],"tags":["android","configuration","validation","cache","builder","videocache"],"backgroundTag":null,"analyzedSha":"e5d74d3aa9d7fb1393a879e33ee380f8f41354f1","analyzedAt":"2026-08-14T11:56:11.997Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}