{"record":{"id":"a5383ebd1687aaa2","repo":"Unity-Technologies/UnityCsReference","slug":"columns-are-no-allowed-to-be-null","errorCode":null,"errorMessage":"columns are no allowed to be null","messagePattern":"columns are no allowed to be null","errorType":"exception","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"Editor/Mono/GUI/TreeView/MultiColumnHeaderState.cs","lineNumber":75,"sourceCode":"                return;\n            }\n\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            }","sourceCodeStart":57,"sourceCodeEnd":93,"githubUrl":"https://github.com/Unity-Technologies/UnityCsReference/blob/225b0fbdb57cc17d094e8056b71f8314aba56f73/Editor/Mono/GUI/TreeView/MultiColumnHeaderState.cs#L57-L93","documentation":"Thrown by the MultiColumnHeaderState constructor when the columns array argument is null. A header state with no column definitions cannot render or sort anything, so null is rejected at construction.","triggerScenarios":"Constructing 'new MultiColumnHeaderState(null)'; passing a column-builder method that returned null on failure.","commonSituations":"Dynamic column generation that returns null when no columns are applicable; deserialization helpers that yield null for empty definitions.","solutions":["Always pass a non-null Column[]; use an empty-safe builder that guarantees at least one column.","If no columns are applicable, avoid constructing the state at all rather than passing null.","Null-coalesce at the call site: columns ?? throw new InvalidOperationException(\"no columns defined\")."],"exampleFix":"// before\nvar st = new MultiColumnHeaderState(BuildColumns()); // may be null\n\n// after\nColumn[] cols = BuildColumns() ?? throw new InvalidOperationException(\"No columns defined\");\nvar st = new MultiColumnHeaderState(cols);","handlingStrategy":"validation","validationCode":"if (columns == null) throw new ArgumentNullException(nameof(columns)); // or supply defaults","typeGuard":"static bool HasColumns(Column[] c) => c != null && c.Length > 0;","tryCatchPattern":null,"preventionTips":["Guarantee column builders return non-null arrays.","Null-coalesce at the construction call site.","Avoid constructing MultiColumnHeaderState when no columns exist."],"tags":["unity-editor","treeview","multicolumn","null-check"],"backgroundTag":null,"analyzedSha":"225b0fbdb57cc17d094e8056b71f8314aba56f73","analyzedAt":"2026-08-13T19:07:19.849Z","schemaVersion":2},"datasetVersion":"2026-08-13T19:17:28.613Z"}