Skip to content

[fix-finder] Remove null-forgiving operator (!) in BaseTest.AssertApkSigned #12035

Description

@github-actions

Problem

The repo coding rule states the null-forgiving operator (!) must never be used in C# code — always refactor to an explicit null check that throws. BaseTest.cs uses proc!.StandardOutput after Process.Start, which can return null. If Process.Start returns null, the current code produces a raw NullReferenceException instead of a clear failure message.

Location

  • File(s): src/Xamarin.Android.Build.Tasks/Tests/Xamarin.Android.Build.Tests/Utilities/BaseTest.cs
  • Line(s): 493–494

Current Code

using var proc = Process.Start (psi);
string stdout = proc!.StandardOutput.ReadToEnd ();

Suggested Fix

Replace the null-forgiving operator with a null-coalescing throw so the process handle is validated once and the remaining usages (proc.StandardError, proc.WaitForExit, proc.ExitCode) stay non-null:

using var proc = Process.Start (psi) ?? throw new InvalidOperationException ($"Failed to start '{apksignerExe}'.");
string stdout = proc.StandardOutput.ReadToEnd ();

This removes the only ! in this method; lines 495–497 already dereference proc without ! and need no change.

Guidelines

  • Follow dotnet/android formatting: tabs, space before (, Mono style.
  • A ?? throw expression is C# 7+ and compiles on the project's TFM ($(DotNetStableTargetFramework)).
  • Do not introduce any other ! usages.

Acceptance Criteria

  • proc!.StandardOutput no longer uses the null-forgiving operator
  • Process.Start result is validated with an explicit throw
  • All tests pass
  • No new warnings introduced

Fix-finder metadata

  • Script: 02-null-forgiving-operator
  • Score: 30/30 (actionability: 10, safety: 10, scope: 10)

Generated by Nightly Fix Finder · 67.8 AIC · ⌖ 17.2 AIC · ⊞ 9.3K ·

  • expires on Jul 18, 2026, 2:25 AM UTC

Metadata

Metadata

Type

No type

Fields

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