{"record":{"id":"d465542db81c262b","repo":"AvaloniaUI/Avalonia","slug":"items","errorCode":null,"errorMessage":"items","messagePattern":"items","errorType":"exception","errorClass":"ArgumentNullException","httpStatus":null,"severity":"error","filePath":"src/Avalonia.Base/Collections/AvaloniaList.cs","lineNumber":364,"sourceCode":"        /// <param name=\"item\">The item.</param>\n        public virtual void Insert(int index, T item)\n        {\n            Validator?.Validate(item);\n\n            OnMutating();\n\n            _inner.Insert(index, item);\n            NotifyAdd(item, index);\n        }\n\n        /// <summary>\n        /// Inserts multiple items at the specified index.\n        /// </summary>\n        /// <param name=\"index\">The index.</param>\n        /// <param name=\"items\">The items.</param>\n        public virtual void InsertRange(int index, IEnumerable<T> items)\n        {\n            _ = items ?? throw new ArgumentNullException(nameof(items));\n\n            bool willRaiseCollectionChanged = _collectionChanged != null;\n            bool hasValidation = Validator is not null;\n\n            if (items is IList list)\n            {\n                if (list.Count > 0)\n                {\n                    OnMutating();\n\n                    if (list is ICollection<T> collection)\n                    {\n                        if (hasValidation)\n                        {\n                            foreach (T item in collection)\n                            {\n                                Validator!.Validate(item);\n                            }","sourceCodeStart":346,"sourceCodeEnd":382,"githubUrl":"https://github.com/AvaloniaUI/Avalonia/blob/11c542726898ae954a1ef668c65ec79ec92ab17d/src/Avalonia.Base/Collections/AvaloniaList.cs#L346-L382","documentation":"ArgumentNullException thrown by AvaloniaList.InsertRange when the items enumerable is null. The method iterates the sequence to insert items and cannot proceed without one.","triggerScenarios":"Calling list.InsertRange(index, null) or passing a null IEnumerable<T> from an uninitialized property/method result.","commonSituations":"A LINQ/select chain yielding null, an optional collection argument forwarded unchecked, or a property that lazily initializes but is accessed before assignment.","solutions":["Pass a non-null enumerable (e.g. Array.Empty<T>() or an empty list) when there is nothing to insert.","Null-check the source before calling InsertRange and skip the call when null.","Fix the upstream producer so it never returns null for a collection."],"exampleFix":"// before\nlist.InsertRange(0, maybeNullItems);\n\n// after\nif (maybeNullItems is not null) list.InsertRange(0, maybeNullItems);","handlingStrategy":"validation","validationCode":"if (items is null) return;\nlist.InsertRange(index, items);","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Null-check enumerables before InsertRange or pass Array.Empty<T>().","Never let collection-typed properties return null; return empty collections.","Validate method parameters that represent item sequences."],"tags":["avalonia","collections","list","null-argument"],"backgroundTag":null,"analyzedSha":"11c542726898ae954a1ef668c65ec79ec92ab17d","analyzedAt":"2026-08-13T11:57:40.261Z","schemaVersion":2},"datasetVersion":"2026-08-13T14:17:21.547Z"}