{"record":{"id":"dd54b12e2ff09dc7","repo":"tui-cs/Terminal.Gui","slug":"fortree","errorCode":null,"errorMessage":"forTree","messagePattern":"forTree","errorType":"exception","errorClass":"ArgumentNullException","httpStatus":null,"severity":"error","filePath":"Terminal.Gui/Views/TreeView/TreeViewTextFilter.cs","lineNumber":18,"sourceCode":"namespace Terminal.Gui.Views;\n\n/// <summary>\n///     <see cref=\"ITreeViewFilter{T}\"/> implementation which searches the <see cref=\"TreeView{T}.AspectGetter\"/> of\n///     the model for the given <see cref=\"Text\"/>.\n/// </summary>\n/// <typeparam name=\"T\"></typeparam>\npublic class TreeViewTextFilter<T> : ITreeViewFilter<T> where T : class\n{\n    private readonly TreeView<T> _forTree;\n\n    /// <summary>\n    ///     Creates a new instance of the filter for use with <paramref name=\"forTree\"/>. Set <see cref=\"Text\"/> to begin\n    ///     filtering.\n    /// </summary>\n    /// <param name=\"forTree\">The tree view this filter applies to.</param>\n    /// <exception cref=\"ArgumentNullException\"></exception>\n    public TreeViewTextFilter (TreeView<T> forTree) => _forTree = forTree ?? throw new ArgumentNullException (nameof (forTree));\n\n    /// <summary>The case sensitivity of the search match. Defaults to <see cref=\"StringComparison.OrdinalIgnoreCase\"/>.</summary>\n    public StringComparison Comparer { get; set; } = StringComparison.OrdinalIgnoreCase;\n\n    /// <summary>The text that will be searched for in the <see cref=\"TreeView{T}\"/></summary>\n    public string Text\n    {\n        get;\n        set\n        {\n            field = value;\n            RefreshTreeView ();\n        }\n    } = string.Empty;\n\n    /// <summary>\n    ///     Returns <see langword=\"true\"/> if there is no <see cref=\"Text\"/> or the text matches the\n    ///     <see cref=\"TreeView{T}.AspectGetter\"/> of the <paramref name=\"model\"/>.","sourceCodeStart":1,"sourceCodeEnd":36,"githubUrl":"https://github.com/tui-cs/Terminal.Gui/blob/2e47b11478db083499917f2ad27c34d30efb0df1/Terminal.Gui/Views/TreeView/TreeViewTextFilter.cs#L1-L36","documentation":"Thrown by the TreeViewTextFilter<T> constructor (ArgumentNullException, param 'forTree') when the forTree argument is null. The filter holds a reference to the TreeView it filters and calls back into it on every Text change (RefreshTreeView), so a null tree would cause NullReferenceExceptions later. The constructor rejects null up front.","triggerScenarios":"Constructing new TreeViewTextFilter<T>(null), or passing a tree variable that is null because it was not yet initialised (e.g. filter built before the TreeView in a field-initialiser ordering issue).","commonSituations":"Field/property initialisation order where the filter is created before the tree; factory/DI code that receives a null tree due to a registration miss; tests new'ing the filter without a tree.","solutions":["Ensure the TreeView is constructed before the filter: _tree = new TreeView<T>(); _filter = new TreeViewTextFilter<T>(_tree);","If the tree may be unknown at construction, defer creating the filter until the tree is available, or set it via a method that accepts a non-null tree.","In DI, register the TreeView first and inject it into the filter factory."],"exampleFix":"// before\n_filter = new TreeViewTextFilter<T>(_tree); // _tree still null -> throws 178\n\n// after\n_tree = new TreeView<T>();\n_filter = new TreeViewTextFilter<T>(_tree);","handlingStrategy":"validation","validationCode":"_tree = new TreeView<T>();\n_filter = new TreeViewTextFilter<T>(_tree); // tree guaranteed non-null","typeGuard":"static bool TreeIsReady<T>(TreeView<T>? t) => t is not null;","tryCatchPattern":null,"preventionTips":["Construct the TreeView before the filter.","Watch field-initialiser ordering when both are declared inline.","In DI, register the TreeView before the filter factory."],"tags":["treeview","nullable","constructor","precondition"],"backgroundTag":null,"analyzedSha":"2e47b11478db083499917f2ad27c34d30efb0df1","analyzedAt":"2026-08-13T19:20:08.826Z","schemaVersion":2},"datasetVersion":"2026-08-14T00:17:13.853Z"}