{"record":{"id":"95cb7fe71e0a7320","repo":"stride3d/stride","slug":"array-is-null","errorCode":null,"errorMessage":"Array is null","messagePattern":"Array is null","errorType":"exception","errorClass":"ArgumentNullException","httpStatus":null,"severity":"error","filePath":"sources/core/Stride.Core/Collections/Dequeue.cs","lineNumber":251,"sourceCode":"    /// Copies the elements of this list to an <see cref=\"T:System.Array\"/>, starting at a particular <see cref=\"T:System.Array\"/> index.\n    /// </summary>\n    /// <param name=\"array\">The one-dimensional <see cref=\"T:System.Array\"/> that is the destination of the elements copied from this slice. The <see cref=\"T:System.Array\"/> must have zero-based indexing.</param>\n    /// <param name=\"arrayIndex\">The zero-based index in <paramref name=\"array\"/> at which copying begins.</param>\n    /// <exception cref=\"T:System.ArgumentNullException\">\n    /// <paramref name=\"array\"/> is null.\n    /// </exception>\n    /// <exception cref=\"T:System.ArgumentOutOfRangeException\">\n    /// <paramref name=\"arrayIndex\"/> is less than 0.\n    /// </exception>\n    /// <exception cref=\"T:System.ArgumentException\">\n    /// <paramref name=\"arrayIndex\"/> is equal to or greater than the length of <paramref name=\"array\"/>.\n    /// -or-\n    /// The number of elements in the source <see cref=\"T:System.Collections.Generic.ICollection`1\"/> is greater than the available space from <paramref name=\"arrayIndex\"/> to the end of the destination <paramref name=\"array\"/>.\n    /// </exception>\n    void ICollection<T>.CopyTo(T[] array, int arrayIndex)\n    {\n        if (array == null)\n            throw new ArgumentNullException(nameof(array), \"Array is null\");\n\n        int count = Count;\n        CheckRangeArguments(array.Length, arrayIndex, count);\n        for (int i = 0; i != count; ++i)\n        {\n            array[arrayIndex + i] = this[i];\n        }\n    }\n\n    /// <summary>\n    /// Removes the first occurrence of a specific object from this list.\n    /// </summary>\n    /// <param name=\"item\">The object to remove from this list.</param>\n    /// <returns>\n    /// true if <paramref name=\"item\"/> was successfully removed from this list; otherwise, false. This method also returns false if <paramref name=\"item\"/> is not found in this list.\n    /// </returns>\n    /// <exception cref=\"T:System.NotSupportedException\">\n    /// This list is read-only.","sourceCodeStart":233,"sourceCodeEnd":269,"githubUrl":"https://github.com/stride3d/stride/blob/96fad776d210c221682aac1ccdf4c79dc046fc38/sources/core/Stride.Core/Collections/Dequeue.cs#L233-L269","documentation":"Deque<T>'s explicit ICollection<T>.CopyTo(T[] array, int arrayIndex) implementation copies the deque's elements into a strongly-typed array. It begins with argument validation and throws ArgumentNullException('Array is null') when the destination array is null, before any element is copied or range checks are performed.","triggerScenarios":"Calling deque.CopyTo(null, 0); passing an array field/property that was never initialized (null); forwarding the result of a method that returned null as the destination array.","commonSituations":"Interop with APIs that supply the buffer lazily; deserialization stubs with uninitialized target buffers; refactors where array allocation moved but the CopyTo call did not.","solutions":["Allocate the destination array (new T[deque.Count]) before calling CopyTo.","Use LINQ Enumerable.ToArray(deque) when a fresh snapshot array is acceptable.","Guard with a null check before the call and handle the empty case."],"exampleFix":"// before\nT[] buffer = GetBufferMaybeNull();\ndeque.CopyTo(buffer, 0); // throws when buffer is null\n\n// after\nT[] buffer = GetBufferMaybeNull() ?? new T[deque.Count];\ndeque.CopyTo(buffer, 0);","handlingStrategy":"type-guard","validationCode":"if (destination == null)\n    destination = new T[deque.Count];\ndeque.CopyTo(destination, 0);","typeGuard":"static bool IsValidDestination<T>(T[]? array, int arrayIndex) =>\n    array is not null && arrayIndex >= 0 && arrayIndex <= array.Length;","tryCatchPattern":"try\n{\n    deque.CopyTo(destination, 0);\n}\ncatch (ArgumentNullException ex) when (ex.ParamName == \"array\")\n{\n    destination = new T[deque.Count];\n    deque.CopyTo(destination, 0);\n}","preventionTips":["Allocate the destination array with new T[deque.Count] immediately before CopyTo.","Prefer deque.ToArray() for snapshots.","Initialize array fields at declaration or in constructors so they are never null at use sites."],"tags":["csharp","stride-core","collections","null-reference"],"backgroundTag":"null-argument","analyzedSha":"96fad776d210c221682aac1ccdf4c79dc046fc38","analyzedAt":"2026-09-14T02:59:31.279Z","contentChangedAt":"2026-09-14T02:59:31.279Z","schemaVersion":2},"datasetVersion":"2026-09-15T23:17:13.987Z"}