You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
src/Xamarin.Android.Build.Tasks/Utilities/RtxtWriter.cs is shipped product code that has not yet opted in to nullable reference types (NRT). Enabling #nullable enable improves null-safety and moves this file toward the repo-wide NRT goal. This is a tiny, self-contained utility, making it a low-risk candidate.
usingSystem;usingSystem.Collections.Generic;usingSystem.IO;usingSystem.Text;usingSystem.Linq;usingMicrosoft.Android.Build.Tasks;usingMicrosoft.Build.Utilities;namespaceXamarin.Android.Tasks{/// Write a list of Item to a file///publicclassRtxtWriter{publicvoidWrite(stringfile,IList<R>items){using(varsw=MemoryStreamPool.Shared.CreateStreamWriter()){foreach(variteminitems){sw.WriteLine(item.ToString());}sw.Flush();Files.CopyIfStreamChanged(sw.BaseStream,file);}}}}
Suggested Fix
Add #nullable enable as the very first line (no preceding blank lines) and add explicit null checks for the two reference-type parameters (file and items). The owning project (Xamarin.Android.Build.Tasks.csproj) targets netstandard2.0, so ArgumentNullException.ThrowIfNull is NOT available — use the explicit two-line form:
#nullable enable
usingSystem;usingSystem.Collections.Generic;usingSystem.IO;usingSystem.Text;usingSystem.Linq;usingMicrosoft.Android.Build.Tasks;usingMicrosoft.Build.Utilities;namespaceXamarin.Android.Tasks{/// Write a list of Item to a file///publicclassRtxtWriter{publicvoidWrite(stringfile,IList<R>items){if(file==null)thrownewArgumentNullException(nameof(file));if(items==null)thrownewArgumentNullException(nameof(items));using(varsw=MemoryStreamPool.Shared.CreateStreamWriter()){foreach(variteminitems){sw.WriteLine(item.ToString());}sw.Flush();Files.CopyIfStreamChanged(sw.BaseStream,file);}}}}
Note: R is a struct (defined in RtxtParser.cs), so IList<R> needs no element-level null annotations and no ! operator is required anywhere.
Guidelines
Add #nullable enable at the top with no preceding blank lines.
Never use the ! (null-forgiving) operator — check for null explicitly.
The project is netstandard2.0; use if (x == null) throw new ArgumentNullException (nameof (x)); — do NOT use ArgumentNullException.ThrowIfNull (it does not exist in netstandard2.0 and broke the build in PR Enable nullable reference types in XAJavaTypeScanner.cs #11455).
Problem
src/Xamarin.Android.Build.Tasks/Utilities/RtxtWriter.csis shipped product code that has not yet opted in to nullable reference types (NRT). Enabling#nullable enableimproves null-safety and moves this file toward the repo-wide NRT goal. This is a tiny, self-contained utility, making it a low-risk candidate.Location
src/Xamarin.Android.Build.Tasks/Utilities/RtxtWriter.csCurrent Code
Suggested Fix
Add
#nullable enableas the very first line (no preceding blank lines) and add explicit null checks for the two reference-type parameters (fileanditems). The owning project (Xamarin.Android.Build.Tasks.csproj) targetsnetstandard2.0, soArgumentNullException.ThrowIfNullis NOT available — use the explicit two-line form:Note:
Ris astruct(defined inRtxtParser.cs), soIList<R>needs no element-level null annotations and no!operator is required anywhere.Guidelines
#nullable enableat the top with no preceding blank lines.!(null-forgiving) operator — check for null explicitly.netstandard2.0; useif (x == null) throw new ArgumentNullException (nameof (x));— do NOT useArgumentNullException.ThrowIfNull(it does not exist in netstandard2.0 and broke the build in PR Enable nullable reference types in XAJavaTypeScanner.cs #11455).(.Acceptance Criteria
#nullable enableis the first line of the file!null-forgiving operator is usedFix-finder metadata
01-nullable-reference-types30/30(actionability: 10, safety: 10, scope: 10)