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
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 · ◷
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.csusesproc!.StandardOutputafterProcess.Start, which can returnnull. IfProcess.Startreturnsnull, the current code produces a rawNullReferenceExceptioninstead of a clear failure message.Location
src/Xamarin.Android.Build.Tasks/Tests/Xamarin.Android.Build.Tests/Utilities/BaseTest.csCurrent Code
Suggested Fix
Replace the null-forgiving operator with a null-coalescing
throwso the process handle is validated once and the remaining usages (proc.StandardError,proc.WaitForExit,proc.ExitCode) stay non-null:This removes the only
!in this method; lines 495–497 already dereferenceprocwithout!and need no change.Guidelines
(, Mono style.?? throwexpression is C# 7+ and compiles on the project's TFM ($(DotNetStableTargetFramework)).!usages.Acceptance Criteria
proc!.StandardOutputno longer uses the null-forgiving operatorProcess.Startresult is validated with an explicit throwFix-finder metadata
02-null-forgiving-operator30/30(actionability: 10, safety: 10, scope: 10)