Problem
src/Xamarin.Android.Build.Tasks/MamJsonToXml.cs does not opt into nullable reference types and uses the null! operator on line 19, which violates repository conventions.
Location
- File:
src/Xamarin.Android.Build.Tasks/MamJsonToXml.cs
Current Code
using System;
using System.IO;
using Microsoft.Build.Framework;
using Microsoft.Build.Utilities;
using Microsoft.Android.Build.Tasks;
namespace Xamarin.Android.Tasks
{
public class MamJsonToXml : AndroidTask
{
public override string TaskPrefix => "A2C";
[Required]
public ITaskItem[] MappingFiles { get; set; } = [];
[Required]
public ITaskItem XmlMappingOutput { get; set; } = null!; // NRT - guarded by [Required]
public override bool RunTask ()
{
var parser = new MamJsonParser (this.CreateTaskLogger ());
foreach (var file in MappingFiles) {
parser.Load (file.ItemSpec);
}
var tree = parser.ToXml ();
using (var o = File.CreateText (XmlMappingOutput.ItemSpec)) {
o.WriteLine (tree.ToString ());
}
return true;
}
}
}
Suggested Fix
- Add
#nullable enable as the very first line (no preceding blank lines).
- Replace
null! on the XmlMappingOutput property. Since ITaskItem is a reference type with [Required], use a helper or throw pattern. The simplest compliant approach: declare a backing field initialized to a dummy and use ArgumentNullException.ThrowIfNull in RunTask before use, OR use Microsoft.Android.Build.Tasks.TaskItemStub.Default if available. If no stub exists, the recommended pattern for [Required] ITaskItem in this repo is:
[Required]
public ITaskItem XmlMappingOutput { get; set; } = new TaskItem ();
This follows the same pattern as [Required] string properties using = "" — it provides a non-null default that MSBuild will overwrite at runtime.
Guidelines
- Never use
! (null-forgiving operator) — this is a hard rule in the repo
- Space before
( and [ (Mono style): File.CreateText (path), array [0]
- Use tabs for indentation
[Required] properties: non-nullable with a sensible default (= "", = [], or = new TaskItem ())
- Add
using Microsoft.Build.Utilities; if TaskItem is not already imported (it is already imported in this file)
Acceptance Criteria
Fix-finder metadata
- Script:
01-nullable-reference-types
- Score:
28/30 (actionability: 10, safety: 8, scope: 10)
Generated by Nightly Fix Finder for issue #11451 · ● 6.9M · ◷
Problem
src/Xamarin.Android.Build.Tasks/MamJsonToXml.csdoes not opt into nullable reference types and uses thenull!operator on line 19, which violates repository conventions.Location
src/Xamarin.Android.Build.Tasks/MamJsonToXml.csCurrent Code
Suggested Fix
#nullable enableas the very first line (no preceding blank lines).null!on theXmlMappingOutputproperty. SinceITaskItemis a reference type with[Required], use a helper or throw pattern. The simplest compliant approach: declare a backing field initialized to a dummy and useArgumentNullException.ThrowIfNullinRunTaskbefore use, OR useMicrosoft.Android.Build.Tasks.TaskItemStub.Defaultif available. If no stub exists, the recommended pattern for[Required] ITaskItemin this repo is:This follows the same pattern as
[Required] stringproperties using= ""— it provides a non-null default that MSBuild will overwrite at runtime.Guidelines
!(null-forgiving operator) — this is a hard rule in the repo(and[(Mono style):File.CreateText (path),array [0][Required]properties: non-nullable with a sensible default (= "",= [], or= new TaskItem ())using Microsoft.Build.Utilities;ifTaskItemis not already imported (it is already imported in this file)Acceptance Criteria
#nullable enableis the first line of the filenull!operator anywhere in the fileXmlMappingOutputhas a non-null default valueFix-finder metadata
01-nullable-reference-types28/30(actionability:10, safety:8, scope:10)