{"record":{"id":"bd2b0307990019db","repo":"Unity-Technologies/UnityCsReference","slug":"sortascending","errorCode":null,"errorMessage":"sortAscending","messagePattern":"sortAscending","errorType":"exception","errorClass":"ArgumentNullException","httpStatus":null,"severity":"error","filePath":"Editor/Mono/GUI/TreeView/MultiColumnHeader.cs","lineNumber":75,"sourceCode":"                if (value == null)\n                    throw new ArgumentNullException(\"state\", \"MultiColumnHeader state is not allowed to be null\");\n                m_State = value;\n            }\n        }\n\n        public MultiColumnHeader(MultiColumnHeaderState state)\n        {\n            m_State = state;\n            m_HeaderButtonsControlID = GUIUtility.GetPermanentControlID();\n        }\n\n        public void SetSortingColumns(int[] columnIndices, bool[] sortAscending)\n        {\n            if (columnIndices == null)\n                throw new ArgumentNullException(\"columnIndices\");\n\n            if (sortAscending == null)\n                throw new ArgumentNullException(\"sortAscending\");\n\n            if (columnIndices.Length != sortAscending.Length)\n                throw new ArgumentException(\"Input arrays should have same length\");\n\n            if (columnIndices.Length > state.maximumNumberOfSortedColumns)\n                throw new ArgumentException(\"The maximum number of sorted columns is \" + state.maximumNumberOfSortedColumns + \". Trying to set \" + columnIndices.Length + \" columns.\");\n\n            if (columnIndices.Length != columnIndices.DistinctCount())\n                throw new ArgumentException(\"Duplicate column indices are not allowed\", \"columnIndices\");\n\n            bool changed = false;\n\n            if (!columnIndices.AsSpan().SequenceEqual(state.sortedColumns))\n            {\n                state.sortedColumns = columnIndices;\n                changed = true;\n            }\n","sourceCodeStart":57,"sourceCodeEnd":93,"githubUrl":"https://github.com/Unity-Technologies/UnityCsReference/blob/225b0fbdb57cc17d094e8056b71f8314aba56f73/Editor/Mono/GUI/TreeView/MultiColumnHeader.cs#L57-L93","documentation":"Thrown by MultiColumnHeader.SetSortingColumns when the sortAscending boolean array is null. Each column index must have a corresponding ascending/descending flag, so a null flags array is rejected.","triggerScenarios":"Calling SetSortingColumns(columnIndices, null); providing column indices but omitting the sort directions.","commonSituations":"Forgetting to build the parallel boolean array; a default-ascending shortcut that passes null intending 'all ascending'.","solutions":["Construct a boolean array matching the length of columnIndices (e.g. all true for ascending).","Use 'Array.Empty<bool>()' when columnIndices is also empty.","Generate the flags from a sort definition before calling."],"exampleFix":"// before\nheader.SetSortingColumns(cols, null);\n\n// after\nbool[] ascending = cols.Select(c => true).ToArray();\nheader.SetSortingColumns(cols, ascending);","handlingStrategy":"validation","validationCode":"bool[] asc = (sortAscending ?? new bool[columnIndices.Length]).ToArray(); if (asc.Length != columnIndices.Length) asc = columnIndices.Select(_ => true).ToArray();","typeGuard":"static bool IsValidFlagsArray(bool[] a, int expected) => a != null && a.Length == expected;","tryCatchPattern":null,"preventionTips":["Always build the flags array in lockstep with the indices array.","Default missing flags to true (ascending) explicitly rather than null.","Derive both arrays from a single sort-specification structure."],"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"}