Problem
SolutionBuilder.cs in the test infrastructure does not opt into nullable reference types, leaving potential null-reference issues undetected at compile time. The owning project (Xamarin.ProjectTools.csproj) already sets <Nullable>annotations</Nullable> and targets $(DotNetStableTargetFramework) (net10.0+), so enabling nullable at the file level is straightforward.
Location
- File:
src/Xamarin.Android.Build.Tasks/Tests/Xamarin.ProjectTools/Common/SolutionBuilder.cs
Current Code
public string SolutionPath { get; set; }
public string SolutionName { get; set; }
SolutionPath is never set in the constructor — it is always assigned via object initializer by callers. Without nullable annotations, the compiler cannot warn about uninitialized usage.
Suggested Fix
- Add
#nullable enable as the very first line of the file (no preceding blank lines).
- Make
SolutionPath nullable since it is not set in the constructor:
public string? SolutionPath { get; set; }
- Keep
SolutionName non-nullable (it is set in the constructor) and give it a default:
public string SolutionName { get; set; } = "";
(The constructor already assigns it, but the default satisfies the compiler for the window before the constructor body runs.)
- In
Dispose, guard the Directory.Delete call since SolutionPath is now nullable:
if (!string.IsNullOrEmpty (SolutionPath))
Directory.Delete (SolutionPath, recursive: true);
Do NOT use the ! (null-forgiving) operator anywhere. Use explicit null checks or ArgumentNullException.ThrowIfNull where needed (net10.0+ TFM allows ThrowIfNull).
Guidelines
- Follow the repo's nullable conventions (see
.github/copilot-instructions.md)
- Use
x.IsNullOrEmpty () extension method instead of string.IsNullOrEmpty (x) where applicable
- Use tabs for indentation (Mono style)
- Space before parentheses:
Method (), array [0]
- Preserve existing formatting and comments
Acceptance Criteria
Fix-finder metadata
- Script:
01-nullable-reference-types
- Score:
27/30 (actionability: 9, safety: 9, scope: 9)
Generated by Nightly Fix Finder for issue #11451 · ● 18.4M · ◷
Problem
SolutionBuilder.csin the test infrastructure does not opt into nullable reference types, leaving potential null-reference issues undetected at compile time. The owning project (Xamarin.ProjectTools.csproj) already sets<Nullable>annotations</Nullable>and targets$(DotNetStableTargetFramework)(net10.0+), so enabling nullable at the file level is straightforward.Location
src/Xamarin.Android.Build.Tasks/Tests/Xamarin.ProjectTools/Common/SolutionBuilder.csCurrent Code
SolutionPathis never set in the constructor — it is always assigned via object initializer by callers. Without nullable annotations, the compiler cannot warn about uninitialized usage.Suggested Fix
#nullable enableas the very first line of the file (no preceding blank lines).SolutionPathnullable since it is not set in the constructor:SolutionNamenon-nullable (it is set in the constructor) and give it a default:Dispose, guard theDirectory.Deletecall sinceSolutionPathis now nullable:Do NOT use the
!(null-forgiving) operator anywhere. Use explicit null checks orArgumentNullException.ThrowIfNullwhere needed (net10.0+ TFM allowsThrowIfNull).Guidelines
.github/copilot-instructions.md)x.IsNullOrEmpty ()extension method instead ofstring.IsNullOrEmpty (x)where applicableMethod (),array [0]Acceptance Criteria
#nullable enableadded as the first line of the fileSolutionPathisstring?;SolutionNamehas a default value= ""!(null-forgiving operator) used anywhere in the fileFix-finder metadata
01-nullable-reference-types27/30(actionability: 9, safety: 9, scope: 9)