Problem
src/Xamarin.Android.Build.Tasks/Utilities/XAJavaTypeScanner.cs does not opt into nullable reference types (#nullable enable), missing out on compile-time null safety checks.
Location
- File:
src/Xamarin.Android.Build.Tasks/Utilities/XAJavaTypeScanner.cs
Current Code
The file lacks #nullable enable and uses String.IsNullOrEmpty instead of the extension method:
string? hasMonoAndroidReferenceMetadata = assembly.GetMetadata ("HasMonoAndroidReference");
if (String.IsNullOrEmpty (hasMonoAndroidReferenceMetadata)) {
Suggested Fix
- Add
#nullable enable as the very first line (no preceding blank lines)
- Replace
String.IsNullOrEmpty (hasMonoAndroidReferenceMetadata) with hasMonoAndroidReferenceMetadata.IsNullOrEmpty () (extension method from xamarin-android-tools)
- Review all parameters and fields for proper nullability annotations — the constructor parameters
log, cache are non-null by contract so they should remain non-nullable
- The
AddJavaType method is public — ensure its parameters are checked: add ArgumentNullException.ThrowIfNull (type) and ArgumentNullException.ThrowIfNull (types) at the entry
- Never use the
! (null-forgiving) operator — always check for null explicitly
Guidelines
- Use tabs (not spaces), Mono formatting style (space before
( and [)
- Use
ArgumentNullException.ThrowIfNull () for null checks (this is a .NET 10+ project)
- Use
x.IsNullOrEmpty () extension method instead of string.IsNullOrEmpty (x)
- Do not add
#region / #endregion
- Ensure the file compiles cleanly with no new warnings
Acceptance Criteria
Fix-finder metadata
- Script:
01-nullable-reference-types
- Score:
27/30 (actionability: 10, safety: 9, scope: 8)
Generated by Nightly Fix Finder for issue #11451 · ● 6.8M · ◷
Problem
src/Xamarin.Android.Build.Tasks/Utilities/XAJavaTypeScanner.csdoes not opt into nullable reference types (#nullable enable), missing out on compile-time null safety checks.Location
src/Xamarin.Android.Build.Tasks/Utilities/XAJavaTypeScanner.csCurrent Code
The file lacks
#nullable enableand usesString.IsNullOrEmptyinstead of the extension method:Suggested Fix
#nullable enableas the very first line (no preceding blank lines)String.IsNullOrEmpty (hasMonoAndroidReferenceMetadata)withhasMonoAndroidReferenceMetadata.IsNullOrEmpty ()(extension method from xamarin-android-tools)log,cacheare non-null by contract so they should remain non-nullableAddJavaTypemethod is public — ensure its parameters are checked: addArgumentNullException.ThrowIfNull (type)andArgumentNullException.ThrowIfNull (types)at the entry!(null-forgiving) operator — always check for null explicitlyGuidelines
(and[)ArgumentNullException.ThrowIfNull ()for null checks (this is a .NET 10+ project)x.IsNullOrEmpty ()extension method instead ofstring.IsNullOrEmpty (x)#region/#endregionAcceptance Criteria
#nullable enableadded as the first line of the fileString.IsNullOrEmptyreplaced with.IsNullOrEmpty ()extension methodArgumentNullException.ThrowIfNull!(null-forgiving operator)Fix-finder metadata
01-nullable-reference-types27/30(actionability: 10, safety: 9, scope: 8)