{"record":{"id":"72bc8bd8c3a2776e","repo":"Unity-Technologies/UnityCsReference","slug":"invalid-list-cannot-be-null","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/ToggleTreeView.cs","lineNumber":79,"sourceCode":"\n    protected override IList<TreeViewItem> BuildRows(TreeViewItem root)\n    {\n        // Reuse cached list (for capacity)\n        if (m_DefaultRows == null)\n            m_DefaultRows = new List<TreeViewItem>(100);\n        m_DefaultRows.Clear();\n\n        if (hasSearch)\n            SearchFullTree(m_DefaultRows);\n        else\n            AddExpandedRows(root, m_DefaultRows);\n        return m_DefaultRows;\n    }\n\n    void SearchFullTree(List<TreeViewItem> rows)\n    {\n        if (rows == null)\n            throw new ArgumentException(\"Invalid list: cannot be null\", nameof(rows));\n\n        var search = searchString;\n        bool searchEnabledState = false;\n        bool searchedEnabledState = false;\n        var match = Regex.Match(search, s_Regex);\n        if (match.Success)\n        {\n            search = match.Groups[1].Value + match.Groups[4].Value;\n            searchEnabledState = true;\n            searchedEnabledState = match.Groups[3].Value == \"true\";\n        }\n\n        var stack = new Stack<TreeViewItem>();\n        stack.Push(rootItem);\n        while (stack.Count > 0)\n        {\n            TreeViewItem current = stack.Pop();\n            if (current.children != null)","sourceCodeStart":61,"sourceCodeEnd":97,"githubUrl":"https://github.com/Unity-Technologies/UnityCsReference/blob/225b0fbdb57cc17d094e8056b71f8314aba56f73/Editor/Mono/GUI/TreeView/ToggleTreeView.cs#L61-L97","documentation":"Thrown by ToggleTreeView.SearchFullTree when the rows list argument is null. The method populates the provided list with search results, so a null list means there is nowhere to store the results. This is a contract violation on the caller side, not a runtime data problem.","triggerScenarios":"Calling SearchFullTree(searchString, null) directly; passing a field that was never initialized; calling GetRows()/search with a list that a previous code path set to null.","commonSituations":"Custom ToggleTreeView subclass overriding row-building logic and forgetting to allocate m_DefaultRows before delegating to SearchFullTree; refactoring that moved list allocation after the search call.","solutions":["Allocate the list before calling SearchFullTree: pass new List<TreeViewItem>() or ensure your cached field is non-null.","If overriding row population, initialize m_DefaultRows in the constructor or at field declaration.","Add a null-check at the call site and allocate lazily if needed."],"exampleFix":"// before\nSearchFullTree(null);\n\n// after\nif (m_DefaultRows == null) m_DefaultRows = new List<TreeViewItem>();\nSearchFullTree(m_DefaultRows);","handlingStrategy":"validation","validationCode":"if (m_DefaultRows == null) m_DefaultRows = new List<TreeViewItem>();\n// now safe to call SearchFullTree","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Always allocate List<TreeViewItem> fields at declaration.","Initialize cached row lists in OnEnable or the constructor.","Never pass null where an output collection is expected."],"tags":["unity","treeview","toggletreeview","null-argument","search"],"backgroundTag":null,"analyzedSha":"225b0fbdb57cc17d094e8056b71f8314aba56f73","analyzedAt":"2026-08-13T19:07:19.849Z","schemaVersion":2},"datasetVersion":"2026-08-13T19:17:28.613Z"}