Problem
LayoutAttribute.Partial.cs explicitly disables nullable reference type analysis even though its owning project enables nullable warnings. The factory legitimately returns null when an activity has no LayoutAttribute, so opting the file in also requires annotating that return path and the SingleOrDefault() result.
Location
- File(s):
src/Xamarin.Android.Build.Tasks/Mono.Android/LayoutAttribute.Partial.cs
- Line(s): 1, 25-30
Current Code
#nullable disable
public static LayoutAttribute FromTypeDefinition (TypeDefinition type, TypeDefinitionCache cache)
{
CustomAttribute attr = type.GetCustomAttributes ("Android.App.LayoutAttribute")
.SingleOrDefault ();
if (attr == null)
return null;
Suggested Fix
Enable nullable analysis and accurately annotate the two values that can be null:
#nullable enable
public static LayoutAttribute? FromTypeDefinition (TypeDefinition type, TypeDefinitionCache cache)
{
CustomAttribute? attr = type.GetCustomAttributes ("Android.App.LayoutAttribute")
.SingleOrDefault ();
if (attr == null)
return null;
No runtime null-check API is needed. The owning Xamarin.Android.Build.Tasks.csproj targets netstandard2.0, has <Nullable>enable</Nullable>, and does not set <LangVersion> locally, so this suggestion uses only nullable annotations supported by the existing project configuration and remains compatible with its lowest TFM. Preserve the existing null check rather than using ArgumentNullException.ThrowIfNull, which is unavailable on netstandard2.0.
Guidelines
- Keep
#nullable enable as the first line with no preceding blank line.
- Do not use the null-forgiving (
!) operator.
- Preserve Mono C# formatting (tabs and a space before
().
Acceptance Criteria
Fix-finder metadata
- Script:
01-nullable-reference-types
- Score:
30/30 (actionability: 10, safety: 10, scope: 10)
Generated by Nightly Fix Finder · gpt56 · 62.6 AIC · ⌖ 13.3 AIC · ⊞ 28.2K · ◷
Problem
LayoutAttribute.Partial.csexplicitly disables nullable reference type analysis even though its owning project enables nullable warnings. The factory legitimately returnsnullwhen an activity has noLayoutAttribute, so opting the file in also requires annotating that return path and theSingleOrDefault()result.Location
src/Xamarin.Android.Build.Tasks/Mono.Android/LayoutAttribute.Partial.csCurrent Code
Suggested Fix
Enable nullable analysis and accurately annotate the two values that can be null:
No runtime null-check API is needed. The owning
Xamarin.Android.Build.Tasks.csprojtargetsnetstandard2.0, has<Nullable>enable</Nullable>, and does not set<LangVersion>locally, so this suggestion uses only nullable annotations supported by the existing project configuration and remains compatible with its lowest TFM. Preserve the existing null check rather than usingArgumentNullException.ThrowIfNull, which is unavailable onnetstandard2.0.Guidelines
#nullable enableas the first line with no preceding blank line.!) operator.().Acceptance Criteria
LayoutAttribute.Partial.csstarts with#nullable enable.FromTypeDefinitionreturnsLayoutAttribute?and itsattrlocal isCustomAttribute?.Xamarin.Android.Build.Tasks.csprojbuilds without nullable diagnostics from this file.Fix-finder metadata
01-nullable-reference-types30/30(actionability:10, safety:10, scope:10)