Skip to content

Enable nullable reference types in XAJavaTypeScanner.cs#11455

Open
Copilot wants to merge 3 commits into
mainfrom
copilot/fix-enable-nullable-reference-types
Open

Enable nullable reference types in XAJavaTypeScanner.cs#11455
Copilot wants to merge 3 commits into
mainfrom
copilot/fix-enable-nullable-reference-types

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented May 22, 2026

Opt XAJavaTypeScanner.cs into #nullable enable for compile-time null safety.

  • Add #nullable enable as the first line
  • Replace String.IsNullOrEmpty() with the .IsNullOrEmpty() extension method from xamarin-android-tools
  • Add ArgumentNullException.ThrowIfNull guards on public AddJavaType parameters
public void AddJavaType (TypeDefinition type, List<TypeDefinition> types)
{
	ArgumentNullException.ThrowIfNull (type);
	ArgumentNullException.ThrowIfNull (types);
	// ...
}

Agent-Logs-Url: https://github.com/dotnet/android/sessions/eefa7fb2-7f0f-4339-8339-2c48677c5f07

Co-authored-by: jonathanpeppers <840039+jonathanpeppers@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix nullable reference types in XAJavaTypeScanner.cs Enable nullable reference types in XAJavaTypeScanner.cs May 22, 2026
Copilot AI requested a review from jonathanpeppers May 22, 2026 16:01
@jonathanpeppers jonathanpeppers marked this pull request as ready for review May 22, 2026 16:26
Copilot AI review requested due to automatic review settings May 22, 2026 16:26
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR opts XAJavaTypeScanner.cs into file-level nullable context and updates a string null/empty check and parameter guarding to improve null-safety within Xamarin.Android.Build.Tasks.

Changes:

  • Added #nullable enable at the top of XAJavaTypeScanner.cs.
  • Replaced String.IsNullOrEmpty(...) with the nullable-aware .IsNullOrEmpty() extension.
  • Added null-argument guards to AddJavaType(...).

Comment thread src/Xamarin.Android.Build.Tasks/Utilities/XAJavaTypeScanner.cs Outdated
ArgumentNullException.ThrowIfNull is not available in netstandard2.0, which
Xamarin.Android.Build.Tasks targets. Replace with explicit null checks.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
jonathanpeppers added a commit that referenced this pull request May 22, 2026
…rowIfNull regressions

PR #11455 emitted `ArgumentNullException.ThrowIfNull` into `Xamarin.Android.Build.Tasks.csproj` (which targets `netstandard2.0` where that API doesn't exist), breaking the build. Two changes to make sure that class of bug can't slip through again:

1. **01-nullable-reference-types.sh** now walks up from each candidate `.cs` file to find its owning `*.csproj` and prints the project's `<TargetFramework[s]>` value next to it. The agent literally cannot miss the TFM now — it's right there in the scan data.

2. **Phase 2.5 (TFM / Language-Version Sanity Check)** added to the prompt. A small `API → minimum TFM` table covers the most common compile-break sources (`ArgumentNullException.ThrowIfNull`/.NET 6, `string.Contains (char)`/netstandard2.1, collection expressions/C# 12, etc.) with safe fallbacks for older TFMs. The instruction explicitly cites PR #11455 so the precedent is on record.

The script's nullable guidance heredoc also gained a CRITICAL section restating the .NET 6 rule with the regression's PR number so the agent reading the scan output sees the warning before the candidates.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

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

4 participants