{"record":{"id":"a4989936c0db5751","repo":"dotnet/machinelearning","slug":"selector","errorCode":null,"errorMessage":"selector","messagePattern":"selector","errorType":"validation","errorClass":"ArgumentNullException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.ML.DataView/DataViewSchema.cs","lineNumber":277,"sourceCode":"\n                public Builder()\n                {\n                    _items = new List<(string Name, DataViewType Type, Delegate Getter, Annotations Annotations)>();\n                }\n\n                /// <summary>\n                /// Add some columns from <paramref name=\"annotations\"/> into our new annotations, by applying <paramref name=\"selector\"/>\n                /// to all the names.\n                /// </summary>\n                /// <param name=\"annotations\">The annotations row to take values from.</param>\n                /// <param name=\"selector\">The predicate describing which annotation columns to keep.</param>\n                public void Add(Annotations annotations, Func<string, bool> selector)\n                {\n                    if (annotations == null)\n                        return;\n\n                    if (selector == null)\n                        throw new ArgumentNullException(nameof(selector));\n\n                    foreach (var column in annotations.Schema)\n                    {\n                        if (selector(column.Name))\n                            _items.Add((column.Name, column.Type, annotations.GetGetterInternal(column.Index), column.Annotations));\n                    }\n                }\n\n                /// <summary>\n                /// Add one annotation column, strongly-typed version.\n                /// </summary>\n                /// <typeparam name=\"TValue\">The type of the value.</typeparam>\n                /// <param name=\"name\">The annotation name.</param>\n                /// <param name=\"type\">The annotation type.</param>\n                /// <param name=\"getter\">The getter delegate.</param>\n                /// <param name=\"annotations\">Annotations of the input column. Note that annotations on an annotation column is somewhat rare\n                /// except for certain types (for example, slot names for a vector, key values for something of key type).</param>\n                public void Add<TValue>(string name, DataViewType type, ValueGetter<TValue> getter, Annotations annotations = null)","sourceCodeStart":259,"sourceCodeEnd":295,"githubUrl":"https://github.com/dotnet/machinelearning/blob/7b76e69cf964daeca3f1377af6bc5543284d56c6/src/Microsoft.ML.DataView/DataViewSchema.cs#L259-L295","documentation":"The DataViewSchema.Builder.Add(Annotations, Func<string,bool>) overload requires a non-null selector predicate that decides which annotation columns to copy. Passing null is treated as a programming error, so the builder throws ArgumentNullException named 'selector'.","triggerScenarios":"Calling builder.Add(sourceAnnotations, null); forwarding a selector variable that is null because an upstream branch never assigned it; generic helper code that passes through an optional predicate without defaulting it.","commonSituations":"Writing a custom IDataView transform that copies a subset of annotations and mistakenly believing null means 'copy all'; refactoring where a previously always-set lambda became conditionally null.","solutions":["Pass a predicate that accepts everything if you want all annotations: name => true","Only call the overload when you genuinely have a filter; otherwise use the non-selective copy path","Assert or default the selector before calling: selector ?? (_ => true)"],"exampleFix":"// before\nbuilder.Add(inputAnnotations, null);\n// after\nbuilder.Add(inputAnnotations, name => true);","handlingStrategy":"validation","validationCode":"if (selector == null)\n    selector = name => true;\nbuilder.Add(sourceAnnotations, selector);","typeGuard":null,"tryCatchPattern":"try { builder.Add(annotations, selector); }\ncatch (ArgumentNullException e) when (e.ParamName == \"selector\")\n{\n    builder.Add(annotations, _ => true);\n}","preventionTips":["Never pass null where a Func<string,bool> is expected; use _ => true for 'copy all'","Null-check optional predicate parameters before forwarding them","Prefer the selective Add overload only when a real filter exists"],"tags":["dotnet","mlnet","argument-null","builder"],"backgroundTag":"null-argument","analyzedSha":"7b76e69cf964daeca3f1377af6bc5543284d56c6","analyzedAt":"2026-09-11T12:35:38.930Z","contentChangedAt":"2026-09-11T12:35:38.930Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}