{"record":{"id":"d291946bf328cc8b","repo":"Unity-Technologies/UnityCsReference","slug":"refreshrows-should-set-valid-list-of-rows","errorCode":null,"errorMessage":"RefreshRows should set valid list of rows.","messagePattern":"RefreshRows should set valid list of rows\\.","errorType":"exception","errorClass":"NullReferenceException","httpStatus":null,"severity":"critical","filePath":"Editor/Mono/GUI/TreeView/TreeViewControl/TreeViewControlDataSource.cs","lineNumber":64,"sourceCode":"                }\n            }\n\n            public override void FetchData()\n            {\n                // Set before BuildRoot and BuildRows so we can call GetRows in them without recursion\n                m_NeedRefreshRows = false;\n\n                // Root\n                if (m_RootItem == null)\n                {\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                {","sourceCodeStart":46,"sourceCodeEnd":82,"githubUrl":"https://github.com/Unity-Technologies/UnityCsReference/blob/225b0fbdb57cc17d094e8056b71f8314aba56f73/Editor/Mono/GUI/TreeView/TreeViewControl/TreeViewControlDataSource.cs#L46-L82","documentation":"Thrown by FetchData after calling BuildRows when the returned rows list is null. BuildRows (or its default implementation, which calls AddExpandedRows) must return a valid IList of rows; null means the row-building step failed or was not implemented correctly.","triggerScenarios":"Overriding BuildRows and returning null; not overriding BuildRows but rootItem having no expanded rows in a path that returns null; BuildRows returning null conditionally when data is empty.","commonSituations":"Custom BuildRows override that returns null on an early-exit path; data source returning null from an internal helper; overriding BuildRows to do custom filtering but forgetting the return.","solutions":["Override BuildRows and always return a non-null IList (return an empty list when there are no rows).","If using the default BuildRows, ensure rootItem is valid and has expandable children.","Replace 'return null;' with 'return new List<TreeViewItem<TIdentifier>>();' in early-exit branches."],"exampleFix":"// before\nprotected override IList<TreeViewItem<int>> BuildRows(TreeViewItem<int> root)\n{\n    if (data.Count == 0) return null;\n    // ...\n}\n\n// after\nprotected override IList<TreeViewItem<int>> BuildRows(TreeViewItem<int> root)\n{\n    var rows = new List<TreeViewItem<int>>();\n    if (data.Count == 0) return rows;\n    // ...\n    return rows;\n}","handlingStrategy":"validation","validationCode":"protected override IList<TreeViewItem<int>> BuildRows(TreeViewItem<int> root)\n{\n    var rows = new List<TreeViewItem<int>>();\n    // populate...\n    return rows; // never null\n}","typeGuard":"static bool IsValidRows<T>(IList<TreeViewItem<T>> rows) => rows != null;","tryCatchPattern":null,"preventionTips":["Always return a non-null list from BuildRows, even if empty.","Replace early-return nulls with early-return empty lists.","Test BuildRows with empty data sets."],"tags":["unity","treeview","buildrows","null-reference","datasource"],"backgroundTag":null,"analyzedSha":"225b0fbdb57cc17d094e8056b71f8314aba56f73","analyzedAt":"2026-08-13T19:07:19.849Z","schemaVersion":2},"datasetVersion":"2026-08-13T19:17:28.613Z"}