{"record":{"id":"e2a1c65e55b2840a","repo":"Unity-Technologies/UnityCsReference","slug":"columns-array-should-at-least-have-one-column-it","errorCode":null,"errorMessage":"columns array should at least have one column: it is empty","messagePattern":"columns array should at least have one column: it is empty","errorType":"exception","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"Editor/Mono/GUI/TreeView/MultiColumnHeaderState.cs","lineNumber":77,"sourceCode":"\n#pragma warning disable UA2001 // The Banned API Analyzer produces compile errors for any new Linq code. This pre-existing usage has been suppressed, but should be rewritten if possible.\n            destination.m_VisibleColumns = source.m_VisibleColumns.ToArray();\n#pragma warning restore UA2001\n            destination.m_SortedColumns = new List<int>(source.m_SortedColumns);\n\n            for (int i = 0; i < destination.m_Columns.Length; ++i)\n            {\n                destination.m_Columns[i].width = source.m_Columns[i].width;\n                destination.m_Columns[i].sortedAscending = source.m_Columns[i].sortedAscending;\n            }\n        }\n\n        public MultiColumnHeaderState(Column[] columns)\n        {\n            if (columns == null)\n                throw new ArgumentException(\"columns are no allowed to be null\", \"columns\");\n            if (columns.Length == 0)\n                throw new ArgumentException(\"columns array should at least have one column: it is empty\", \"columns\");\n\n            m_Columns = columns;\n            m_SortedColumns = new List<int>();\n\n            // Default to all visible\n            m_VisibleColumns = new int[m_Columns.Length];\n            for (int i = 0; i < m_Columns.Length; ++i)\n                m_VisibleColumns[i] = i;\n        }\n\n        public int sortedColumnIndex\n        {\n            get\n            {\n                return m_SortedColumns.Count > 0 ? m_SortedColumns[0] : -1;\n            }\n            set\n            {","sourceCodeStart":59,"sourceCodeEnd":95,"githubUrl":"https://github.com/Unity-Technologies/UnityCsReference/blob/225b0fbdb57cc17d094e8056b71f8314aba56f73/Editor/Mono/GUI/TreeView/MultiColumnHeaderState.cs#L59-L95","documentation":"Thrown by the MultiColumnHeaderState constructor when the columns array is non-null but empty. A multi-column header requires at least one column to function, so a zero-length array is invalid.","triggerScenarios":"Passing 'new Column[0]' or Array.Empty<Column>(); a dynamic column source that legitimately produced zero columns.","commonSituations":"Feature-gated column sets where all columns are disabled; a filter that removed every column; an early-returning builder returning an empty array.","solutions":["Ensure the column source yields at least one column; provide a default/fallback column.","Skip constructing the header state when no columns exist and render an empty placeholder UI instead.","Validate columns.Length > 0 before construction and log why no columns were produced."],"exampleFix":"// before\nvar st = new MultiColumnHeaderState(cols); // cols.Length == 0\n\n// after\nif (cols.Length == 0) cols = new[] { new MultiColumnHeaderState.Column { headerContent = new GUIContent(\"-\") } };\nvar st = new MultiColumnHeaderState(cols);","handlingStrategy":"validation","validationCode":"if (columns.Length == 0) columns = new[] { new MultiColumnHeaderState.Column { headerContent = new GUIContent(\"(empty)\") } };","typeGuard":"static bool HasAtLeastOne(Column[] c) => c != null && c.Length > 0;","tryCatchPattern":null,"preventionTips":["Provide a fallback column when dynamic generation yields none.","Render a placeholder instead of constructing an empty-column header.","Log why column generation produced zero entries."],"tags":["unity-editor","treeview","multicolumn","validation"],"backgroundTag":null,"analyzedSha":"225b0fbdb57cc17d094e8056b71f8314aba56f73","analyzedAt":"2026-08-13T19:07:19.849Z","schemaVersion":2},"datasetVersion":"2026-08-13T19:17:28.613Z"}