Skip to content

[fix-finder] Enable nullable reference types in AidlCompiler.cs #11402

@github-actions

Description

@github-actions

Problem

src/Xamarin.Android.Tools.Aidl/AidlCompiler.cs does not have nullable reference types enabled. The file has several fields and parameters that can be null but are typed as non-nullable, which hides potential null reference issues at compile time.

Location

  • File: src/Xamarin.Android.Tools.Aidl/AidlCompiler.cs

Current Code

using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using Irony.Parsing;
using Mono.Cecil;

namespace Xamarin.Android.Tools.Aidl
{
    public class AidlCompiler
    {
        // ...
        Dictionary<string,CompilationUnit> units = new Dictionary<string,CompilationUnit> ();
        string output_path;    // can be null before Run() is called
        string output_ns;      // can be null, checked on line 71

        public event Action<string,string> FileWritten;  // can be null if no subscriber

        // ...
        // Line 75: FileWritten invoked without null check
        FileWritten (file, csharp);

        // Line 82: out parameter set to null without nullable annotation
        public Result Run (string input, out string output, AssemblyDefinition[] references = null, ...)
        {
            // ...
            output = null;  // assigned null but parameter is non-nullable
        }
    }
}

Suggested Fix

  1. Add #nullable enable at the top of the file (no preceding blank lines)
  2. Make nullable fields explicit:
    • string output_path;string? output_path;
    • string output_ns;string? output_ns;
  3. Make the event nullable and use null-conditional invoke:
    • public event Action<string,string> FileWritten;public event Action<string,string>? FileWritten;
    • FileWritten (file, csharp);FileWritten?.Invoke (file, csharp);
  4. Fix method signatures:
    • out string outputout string? output
    • AssemblyDefinition[] references = nullAssemblyDefinition[]? references = null
  5. Do NOT use the ! (null-forgiving) operator anywhere — always handle nulls explicitly

Guidelines

  • This project targets netstandard2.0, so use throw new ArgumentNullException (nameof(parameter)) for null argument checks (not ArgumentNullException.ThrowIfNull)
  • Follow Mono formatting style: space before ( in method calls (e.g., FileWritten?.Invoke (file, csharp))
  • Use "" not string.Empty
  • Do not add <Nullable>enable</Nullable> to the .csproj — only add the per-file #nullable enable directive
  • Use the IsNullOrEmpty() extension method instead of string.IsNullOrEmpty() if applicable

Acceptance Criteria

  • #nullable enable added at the top of AidlCompiler.cs
  • All nullable fields and parameters properly annotated
  • No use of the ! (null-forgiving) operator
  • FileWritten event invoked safely with null-conditional operator
  • File compiles without nullable warnings
  • All existing tests pass

Generated by Nightly Fix Finder · ● 6.7M ·

  • expires on May 25, 2026, 9:56 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