{"record":{"id":"772d05cccbb9efc9","repo":"Unity-Technologies/UnityCsReference","slug":"invalid-list-cannot-be-null-772d05","errorCode":null,"errorMessage":"Invalid list: cannot be null","messagePattern":"Invalid list: cannot be null","errorType":"exception","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"Editor/Mono/GUI/TreeView/TreeViewControl/TreeViewControlDataSource.cs","lineNumber":77,"sourceCode":"                }\n\n                // Rows\n                m_Rows = m_Owner.BuildRows(m_RootItem);\n                if (m_Rows == null)\n                    throw new NullReferenceException(\"RefreshRows should set valid list of rows.\");\n\n                // Custom row rects\n                if (m_Owner.m_OverriddenMethods.hasGetCustomRowHeight)\n                    m_Owner.m_GUI.RefreshRowRects(m_Rows);\n            }\n\n            public void SearchFullTree(string search, List<TreeViewItem<TIdentifier>> result)\n            {\n                if (string.IsNullOrEmpty(search))\n                    throw new ArgumentException(\"Invalid search: cannot be null or empty\", \"search\");\n\n                if (result == null)\n                    throw new ArgumentException(\"Invalid list: cannot be null\", \"result\");\n\n                var stack = new Stack<TreeViewItem<TIdentifier>>();\n                stack.Push(m_RootItem);\n                while (stack.Count > 0)\n                {\n                    TreeViewItem<TIdentifier> current = stack.Pop();\n                    if (current.children != null)\n                    {\n                        foreach (var child in current.children)\n                        {\n                            if (child != null)\n                            {\n                                if (m_Owner.DoesItemMatchSearch(child, search))\n                                    result.Add(child);\n\n                                stack.Push(child);\n                            }\n                        }","sourceCodeStart":59,"sourceCodeEnd":95,"githubUrl":"https://github.com/Unity-Technologies/UnityCsReference/blob/225b0fbdb57cc17d094e8056b71f8314aba56f73/Editor/Mono/GUI/TreeView/TreeViewControl/TreeViewControlDataSource.cs#L59-L95","documentation":"Thrown by TreeViewControlDataSource.SearchFullTree when the result list argument is null. The method writes matching items into the provided list; a null list has no capacity to receive results.","triggerScenarios":"Calling SearchFullTree(search, null); passing a list field that was never initialized; a prior code path setting the result reference to null.","commonSituations":"Custom search invocation that forgets to allocate the results list; refactoring that moved allocation after the call.","solutions":["Allocate the results list before calling: var results = new List<TreeViewItem<TIdentifier>>();","Initialize the cached results field at declaration or in OnEnable.","Add a null guard that allocates on demand."],"exampleFix":"// before\ndataSource.SearchFullTree(search, m_Results); // m_Results is null\n\n// after\nm_Results = m_Results ?? new List<TreeViewItem<TIdentifier>>();\ndataSource.SearchFullTree(search, m_Results);","handlingStrategy":"validation","validationCode":"result = result ?? new List<TreeViewItem<TIdentifier>>();\ndataSource.SearchFullTree(search, result);","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Allocate the result list before calling SearchFullTree.","Initialize list fields at declaration.","Never pass null as an output collection."],"tags":["unity","treeview","search","null-argument","list"],"backgroundTag":null,"analyzedSha":"225b0fbdb57cc17d094e8056b71f8314aba56f73","analyzedAt":"2026-08-13T19:07:19.849Z","schemaVersion":2},"datasetVersion":"2026-08-13T19:17:28.613Z"}