Skip to content

[fix-finder] Enable nullable reference types in JdkPackage.cs #11686

@github-actions

Description

@github-actions

Problem

JdkPackage.cs is shipped product code in the Xamarin.Installer.AndroidSDK project (part of Xamarin.Android.sln). That project does not enable nullable reference types at the project level — its .csproj has no <Nullable> property — so this file is not opted into NRT. It is a clean, immutable data model in which every reference-type property is assigned in the constructor, making it an ideal, low-risk first candidate for opting into nullable reference types.

Location

  • File(s): src/Xamarin.Installer.AndroidSDK/Xamarin.Installer.AndroidSDK/Common/JdkPackage.cs
  • Line(s): top of file (new line 1)

Current Code

using System;
using System.Collections.Generic;
using System.Linq;

namespace Xamarin.Installer.AndroidSDK.Common
{
    public class JdkPackage : IJdkComponent
    {
        public JdkPackage(string displayName, bool obsolete, bool preview, string licenseId, PackageVendor vendor, AndroidRevision revision, List<JdkArchive> archives)
        {
            DisplayName = displayName;
            Obsolete = obsolete;
            Preview = preview;
            Vendor = vendor;
            Revision = revision;
            Archives = archives;
            LicenseID = licenseId;
        }

        public Guid UniqueID { get; } = Guid.NewGuid();
        public string DisplayName { get; }
        // ... bool/string/PackageVendor/AndroidRevision/IList<JdkArchive> members, all get-only ...
    }
}

Suggested Fix

Add #nullable enable as the very first line of the file (no preceding blank lines):

#nullable enable

using System;
using System.Collections.Generic;
using System.Linq;

Then build the Xamarin.Installer.AndroidSDK project. Because the constructor initializes every reference-type property (DisplayName, LicenseID, Vendor, Revision, Archives) and there are no uninitialized non-nullable fields or null-returning members, the file is expected to compile with no new nullable warnings and no further code changes. All constructor parameters and properties are required by design and should remain non-nullable.

Guidelines

  • Add #nullable enable at the very top, with no preceding blank lines (preserve the file's existing UTF-8 BOM/encoding).
  • Never use the ! (null-forgiving) operator — refactor or check for null explicitly.
  • The owning project (Xamarin.Installer.AndroidSDK.csproj) targets netstandard2.0. If any null-validation is ever needed, use the netstandard2.0-compatible form if (x == null) throw new ArgumentNullException (nameof (x)); — do not use ArgumentNullException.ThrowIfNull (x), which does not exist before .NET 6 and will not compile here.
  • Keep all currently-required constructor parameters and properties non-nullable; only mark a member nullable (string?) if it is genuinely optional.
  • Follow the repo's documented nullable reference type conventions.

Acceptance Criteria

  • #nullable enable is added as the first line of JdkPackage.cs.
  • No ! null-forgiving operator is introduced.
  • The Xamarin.Installer.AndroidSDK project builds with no new warnings.
  • All tests pass.
  • No new warnings introduced.

Fix-finder metadata

  • Script: 01-nullable-reference-types
  • Score: 27/30 (actionability: 9, safety: 8, scope: 10)

Generated by Nightly Fix Finder for issue #11685 · 934.9 AIC · ⌖ 49.9 AIC · ⊞ 40.7K ·

  • expires on Jun 24, 2026, 4:28 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