{"record":{"id":"37f5c08579c3053c","repo":"Cysharp/UniTask","slug":"minimumlength","errorCode":null,"errorMessage":"minimumLength","messagePattern":"minimumLength","errorType":"validation","errorClass":"ArgumentOutOfRangeException","httpStatus":null,"severity":"error","filePath":"src/UniTask/Assets/Plugins/UniTask/Runtime/Internal/ArrayPool.cs","lineNumber":38,"sourceCode":"        readonly SpinLock[] locks;\n\n        ArrayPool()\n        {\n            // see: GetQueueIndex\n            buckets = new MinimumQueue<T[]>[18];\n            locks = new SpinLock[18];\n            for (int i = 0; i < buckets.Length; i++)\n            {\n                buckets[i] = new MinimumQueue<T[]>(4);\n                locks[i] = new SpinLock(false);\n            }\n        }\n\n        public T[] Rent(int minimumLength)\n        {\n            if (minimumLength < 0)\n            {\n                throw new ArgumentOutOfRangeException(\"minimumLength\");\n            }\n            else if (minimumLength == 0)\n            {\n                return EmptyArray;\n            }\n\n            var size = CalculateSize(minimumLength);\n            var index = GetQueueIndex(size);\n            if (index != -1)\n            {\n                var q = buckets[index];\n                var lockTaken = false;\n                try\n                {\n                    locks[index].Enter(ref lockTaken);\n\n                    if (q.Count != 0)\n                    {","sourceCodeStart":20,"sourceCodeEnd":56,"githubUrl":"https://github.com/Cysharp/UniTask/blob/ceac8d6946b1125fe782cd171fbcb245b567dbf9/src/UniTask/Assets/Plugins/UniTask/Runtime/Internal/ArrayPool.cs#L20-L56","documentation":"Thrown by ArrayPool<T>.Rent(minimumLength) when minimumLength is negative. The pool sizes internal buckets by the requested length; a negative length is a programming error since no array can have negative size. This is UniTask's internal ArrayPool (mirrors System.Buffers.ArrayPool<T>) used for zero-allocation pooling.","triggerScenarios":"Passing a computed negative value to ArrayPool<T>.Shared.Rent(). The pool is internal to UniTask but the guard is standard argument validation.","commonSituations":"A size calculation that subtracts from an uninitialized or incorrectly computed length, producing a negative result. An off-by-one in buffer sizing logic. Parsing external data that yields a negative count.","solutions":["Clamp the value to zero before calling Rent: var len = Math.Max(0, computedLength);","Trace the upstream calculation that produced the negative value and fix the root cause.","Add a debug assertion or precondition check before the Rent call."],"exampleFix":"// before\nvar buf = ArrayPool<byte>.Shared.Rent(estimatedSize - headerSize); // throws if headerSize > estimatedSize\n\n// after\nvar len = Math.Max(0, estimatedSize - headerSize);\nvar buf = ArrayPool<byte>.Shared.Rent(len);","handlingStrategy":"validation","validationCode":"var safeLength = Math.Max(0, minimumLength);\nvar buf = ArrayPool<T>.Shared.Rent(safeLength);","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Always clamp computed sizes with Math.Max(0, value) before passing to Rent.","Validate parsed/serialized size fields against negative values at the trust boundary.","Use debug assertions to catch negative sizes early during development."],"tags":["array-pool","argument-validation","internal"],"backgroundTag":null,"analyzedSha":"ceac8d6946b1125fe782cd171fbcb245b567dbf9","analyzedAt":"2026-08-13T19:16:39.025Z","schemaVersion":2},"datasetVersion":"2026-08-13T19:17:28.613Z"}