{"record":{"id":"be297d79c2418df4","repo":"Unity-Technologies/UnityCsReference","slug":"invalid-search-cannot-be-null-or-empty","errorCode":null,"errorMessage":"Invalid search: cannot be null or empty","messagePattern":"Invalid search: cannot be null or empty","errorType":"exception","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"Editor/Mono/GUI/TreeView/TreeViewControl/TreeViewControlDataSource.cs","lineNumber":74,"sourceCode":"                {\n                    m_RootItem = m_Owner.BuildRoot();\n                    ValidateRootItem();\n                }\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","sourceCodeStart":56,"sourceCodeEnd":92,"githubUrl":"https://github.com/Unity-Technologies/UnityCsReference/blob/225b0fbdb57cc17d094e8056b71f8314aba56f73/Editor/Mono/GUI/TreeView/TreeViewControl/TreeViewControlDataSource.cs#L56-L92","documentation":"Thrown by TreeViewControlDataSource.SearchFullTree when the search string is null or empty. The method walks the tree pushing items onto a stack and filtering by the search term; an empty/null search would match everything and is treated as a misuse (callers should use the non-search row path instead).","triggerScenarios":"Calling SearchFullTree(string.Empty, result); calling with a null search string; a search field that was cleared but SearchFullTree was still invoked.","commonSituations":"UI search box cleared by the user but the search method was called before checking the empty case; programmatic search with an uninitialized string.","solutions":["Check string.IsNullOrEmpty(search) before calling SearchFullTree and use the normal row-building path instead.","Only call SearchFullTree when the user has entered non-whitespace search text.","Guard: if (string.IsNullOrWhiteSpace(search)) return;"],"exampleFix":"// before\ndataSource.SearchFullTree(searchField, rows); // searchField could be empty\n\n// after\nif (!string.IsNullOrEmpty(searchField))\n    dataSource.SearchFullTree(searchField, rows);\nelse\n    AddExpandedRows(rootItem, rows);","handlingStrategy":"validation","validationCode":"if (!string.IsNullOrEmpty(search))\n    dataSource.SearchFullTree(search, result);\nelse\n    AddExpandedRows(root, result);","typeGuard":"static bool HasSearchText(string s) => !string.IsNullOrEmpty(s);","tryCatchPattern":null,"preventionTips":["Check for null/empty search before calling SearchFullTree.","Route empty searches to the normal row-building path.","Guard against whitespace-only search as well."],"tags":["unity","treeview","search","validation","argument"],"backgroundTag":null,"analyzedSha":"225b0fbdb57cc17d094e8056b71f8314aba56f73","analyzedAt":"2026-08-13T19:07:19.849Z","schemaVersion":2},"datasetVersion":"2026-08-13T19:17:28.613Z"}