Skip to content

[fix-finder] Enable nullable reference types in XAJavaTypeScanner.cs #11454

@github-actions

Description

@github-actions

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

  1. Add #nullable enable as the very first line (no preceding blank lines)
  2. Replace String.IsNullOrEmpty (hasMonoAndroidReferenceMetadata) with hasMonoAndroidReferenceMetadata.IsNullOrEmpty () (extension method from xamarin-android-tools)
  3. 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
  4. The AddJavaType method is public — ensure its parameters are checked: add ArgumentNullException.ThrowIfNull (type) and ArgumentNullException.ThrowIfNull (types) at the entry
  5. 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

  • #nullable enable added as the first line of the file
  • String.IsNullOrEmpty replaced with .IsNullOrEmpty () extension method
  • Public method parameters validated with ArgumentNullException.ThrowIfNull
  • No use of ! (null-forgiving operator)
  • All tests pass
  • No new warnings introduced

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 ·

  • expires on May 29, 2026, 3:40 PM UTC

Metadata

Metadata

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions