Problem
src/Mono.Android.Export/Mono.CodeGeneration/CodeWhen.cs is shipped product code — it compiles into Mono.Android.Export.dll, which ships in the Android runtime pack — but it is not opted into nullable reference types (NRT). Its owning project, Mono.Android.Export, does not set <Nullable> at the project level, so this file compiles in a nullable-oblivious context and gets no compile-time null-safety checking.
This particular file is a clean, low-risk candidate to opt in: the class is already null-correct, so enabling NRT should require only the #nullable enable directive and no logic changes.
Location
- File(s):
src/Mono.Android.Export/Mono.CodeGeneration/CodeWhen.cs
- Line(s): top of file — insert the directive immediately after the
#if !MONOTOUCH guard (currently line 24)
Current Code
The file currently opens like this (license header omitted):
#if !MONOTOUCH
using System;
using System.Diagnostics.CodeAnalysis;
using System.Reflection;
using System.Reflection.Emit;
namespace Mono.CodeGeneration
{
[RequiresUnreferencedCode (MonoAndroidExport.DynamicFeatures)]
internal class CodeWhen: CodeExpression
{
CodeExpression condition;
CodeExpression trueBlock;
CodeExpression falseBlock;
public CodeWhen (CodeExpression condition, CodeExpression trueResult, CodeExpression falseResult)
{
this.condition = condition;
if (condition.GetResultType () != typeof(bool))
throw new InvalidOperationException ("Condition expression is not boolean");
if (trueResult.GetResultType() != falseResult.GetResultType())
throw new InvalidOperationException ("The types of the true and false expressions must be the same");
trueBlock = trueResult;
falseBlock = falseResult;
}
// ... Generate / GenerateCondition / PrintCode / GetResultType ...
}
}
#endif
Suggested Fix
Add #nullable enable on its own line, immediately after the #if !MONOTOUCH directive:
#if !MONOTOUCH
#nullable enable
using System;
using System.Diagnostics.CodeAnalysis;
using System.Reflection;
using System.Reflection.Emit;
No other changes are expected to be necessary, because the class is already null-correct:
- All three reference-type fields (
condition, trueBlock, falseBlock) are unconditionally assigned in the single constructor before it returns, so there is no CS8618 (uninitialized non-nullable field).
- Every method dereferences only non-null parameters or those already-assigned fields.
- Calls into the (still nullable-oblivious) base class
CodeExpression and sibling CodeConditionExpression neither produce nor receive nullable warnings.
If — and only if — the compiler surfaces an unexpected nullable warning, fix it following the repo conventions below. The project targets $(DotNetTargetFramework) (.NET), so any genuine argument null-check should use ArgumentNullException.ThrowIfNull (x); (do not use the explicit netstandard2.0 form here). None is expected.
Guidelines
- Follow the repo's nullable conventions documented in the AI instructions.
- Never use the
! null-forgiving operator — check for null explicitly if a warning genuinely requires it.
- Keep Mono code style: tabs, space before
(, etc. Preserve the existing license header and the #if !MONOTOUCH / #endif guard.
- CI builds with
TreatWarningsAsErrors=true, so any new nullable warning will fail the build — verify a clean build of Mono.Android.Export before finishing.
Acceptance Criteria
Fix-finder metadata
- Script:
01-nullable-reference-types
- Score:
28/30 (actionability: 10, safety: 8, scope: 10)
Generated by Nightly Fix Finder · 1.2K AIC · ⌖ 50.9 AIC · ⊞ 40.6K · ◷
Problem
src/Mono.Android.Export/Mono.CodeGeneration/CodeWhen.csis shipped product code — it compiles intoMono.Android.Export.dll, which ships in the Android runtime pack — but it is not opted into nullable reference types (NRT). Its owning project,Mono.Android.Export, does not set<Nullable>at the project level, so this file compiles in a nullable-oblivious context and gets no compile-time null-safety checking.This particular file is a clean, low-risk candidate to opt in: the class is already null-correct, so enabling NRT should require only the
#nullable enabledirective and no logic changes.Location
src/Mono.Android.Export/Mono.CodeGeneration/CodeWhen.cs#if !MONOTOUCHguard (currently line 24)Current Code
The file currently opens like this (license header omitted):
Suggested Fix
Add
#nullable enableon its own line, immediately after the#if !MONOTOUCHdirective:No other changes are expected to be necessary, because the class is already null-correct:
condition,trueBlock,falseBlock) are unconditionally assigned in the single constructor before it returns, so there is noCS8618(uninitialized non-nullable field).CodeExpressionand siblingCodeConditionExpressionneither produce nor receive nullable warnings.If — and only if — the compiler surfaces an unexpected nullable warning, fix it following the repo conventions below. The project targets
$(DotNetTargetFramework)(.NET), so any genuine argument null-check should useArgumentNullException.ThrowIfNull (x);(do not use the explicitnetstandard2.0form here). None is expected.Guidelines
!null-forgiving operator — check for null explicitly if a warning genuinely requires it.(, etc. Preserve the existing license header and the#if !MONOTOUCH/#endifguard.TreatWarningsAsErrors=true, so any new nullable warning will fail the build — verify a clean build ofMono.Android.Exportbefore finishing.Acceptance Criteria
#nullable enableadded toCodeWhen.cs, immediately after the#if !MONOTOUCHguard.!null-forgiving operator introduced.Mono.Android.Exportbuilds with no new nullable warnings or errors.Fix-finder metadata
01-nullable-reference-types28/30(actionability:10, safety:8, scope:10)