{"record":{"id":"b34aa86273afa1fd","repo":"stride3d/stride","slug":"array","errorCode":null,"errorMessage":"array","messagePattern":"array","errorType":"validation","errorClass":"ArgumentNullException","httpStatus":null,"severity":"error","filePath":"sources/engine/Stride.Particles/Sorters/ArrayPool.cs","lineNumber":31,"sourceCode":"\n        public virtual void Clear()\n        {\n            _pool.Clear();\n        }\n\n        public virtual T[] Allocate(int size)\n        {\n            if (size < 0) throw new ArgumentOutOfRangeException(nameof(size), \"Must be positive.\");\n\n            if (size == 0) return Empty;\n\n            Stack<T[]> candidates;\n            return _pool.TryGetValue(size, out candidates) && candidates.Count > 0 ? candidates.Pop() : new T[size];\n        }\n\n        public virtual void Free(T[] array)\n        {\n            if (array == null) throw new ArgumentNullException(nameof(array));\n\n            if (array.Length == 0) return;\n\n            Stack<T[]> candidates;\n            if (!_pool.TryGetValue(array.Length, out candidates))\n                _pool.Add(array.Length, candidates = new Stack<T[]>());\n            candidates.Push(array);\n        }\n    }\n\n    public class ConcurrentArrayPool<T> : ArrayPool<T> where T : struct\n    {\n        public override T[] Allocate(int size)\n        {\n            lock (this)\n            {\n                return base.Allocate(size);\n            }","sourceCodeStart":13,"sourceCodeEnd":49,"githubUrl":"https://github.com/stride3d/stride/blob/96fad776d210c221682aac1ccdf4c79dc046fc38/sources/engine/Stride.Particles/Sorters/ArrayPool.cs#L13-L49","documentation":"Argument-null validation in ArrayPool.Free: the array being returned to the pool is null. There is no pooled object to release for a null reference, so the method throws ArgumentNullException named 'array'. (Note the sibling Allocate method similarly guards size with 'Must be positive'.)","triggerScenarios":"Calling Free(null) after a failed allocation path or when the buffer variable was never assigned.","commonSituations":"Cleanup/finally blocks in particle sorting code freeing buffers that were never allocated.","solutions":["Initialize buffers to Array.Empty<T>() instead of null","Guard Free calls with a null check","Ensure allocation succeeded before scheduling the free"],"exampleFix":"// before\narrayPool.Free(buffer); // buffer may be null\n// after\nif (buffer != null) arrayPool.Free(buffer);","handlingStrategy":"validation","validationCode":"if (buffer != null)\n    pool.Free(buffer);","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Initialize buffers to Array.Empty<T>() not null","Only free buffers that were successfully allocated","Null-check in cleanup/finally paths"],"tags":["particles","array-pool","null-argument"],"backgroundTag":"null-argument","analyzedSha":"96fad776d210c221682aac1ccdf4c79dc046fc38","analyzedAt":"2026-09-14T02:59:31.279Z","contentChangedAt":"2026-09-14T02:59:31.279Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}