Skip to content

Code Review Bench PR #64401 - [release/10.0] Fix ModelMetadata null reference exception in emitted XMLComment transformers#8

Open
ketkarameya wants to merge 5 commits intobase_pr_64401_20260125_1476from
corrupted_pr_64401_20260125_1476
Open

Code Review Bench PR #64401 - [release/10.0] Fix ModelMetadata null reference exception in emitted XMLComment transformers#8
ketkarameya wants to merge 5 commits intobase_pr_64401_20260125_1476from
corrupted_pr_64401_20260125_1476

Conversation

@ketkarameya
Copy link

@ketkarameya ketkarameya commented Feb 10, 2026

Code Review Bench PR dotnet#64401 - [release/10.0] Fix ModelMetadata null reference exception in emitted XMLComment transformers

Benchmark PR for Gitar evaluation

Original PR: agentic-review-benchmarks#8

Fixes null reference exception in ModelMetadata XMLComment transformers for release/10.0.


Summary by Gitar

  • Fixed null reference exception: Added null-check guard for ModelMetadata in XmlCommentGenerator.Emitter.cs to prevent crashes when route parameters are documented in XML comments but not used by handler methods

  • Regression test coverage: Added SupportsRouteParametersFromControllers() test to validate parameter descriptions in OpenAPI schema for unused route parameters

  • Backward compatible: Uses modern C# pattern (metadata is not null) without affecting existing functionality or introducing breaking changes

desjoerd and others added 5 commits January 25, 2026 11:59
…ment transformers

When a route parameter does not have a bound model it would case a null reference exception because the ModelMetadata on the ParameterDescriptor was null.
This is fixed by adding a null reference check

Fixes dotnet#63757
As I think this was the encoding before my change
Comment on lines 380 to 383
if (methodComment.Remarks is { } remarks)
{
operation.Description = remarks;
operation.Summary = remarks;
}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Bug: Remarks now overwrites Summary instead of setting Description

The change from operation.Description = remarks to operation.Summary = remarks (line 382) means that when both <summary> and <remarks> XML tags are present on a method, the remarks text will overwrite the summary that was just set on line 374.

Previously:

  • <summary>operation.Summary
  • <remarks>operation.Description

Now:

  • <summary>operation.Summary
  • <remarks>operation.Summary (overwrites the summary!)

This seems semantically incorrect. If both tags are provided, the summary is silently lost. The original behavior of mapping remarks to operation.Description makes more sense in the OpenAPI context, where Summary and Description are distinct fields.

Additionally, this change is NOT reflected in any of the 9 snapshot files (they all still have operation.Description = remarks), so the snapshot tests will fail when regenerated.

Was this helpful? React with 👍 / 👎

Suggested change
if (methodComment.Remarks is { } remarks)
{
operation.Description = remarks;
operation.Summary = remarks;
}
if (methodComment.Remarks is { } remarks)
{
operation.Description = remarks;
}
  • Apply suggested fix

if (XmlCommentCache.Cache.TryGetValue(DocumentationCommentIdHelper.NormalizeDocId(propertyDocId), out var propertyComment))
{
var parameter = operation.Parameters?.SingleOrDefault(p => p.Name == metadata.Name);
var parameter = operation.Parameters?.SingleOrDefault(p => p.Name == propertyName);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Bug: Snapshot files not updated for propertyName and other changes

The emitter template has three changes beyond the null-check fix, but the snapshot verification files were only updated for the null-check. The other changes will cause snapshot test failures:

  1. p.Name == metadata.Namep.Name == propertyName (line 452): All 9 snapshot files still use metadata.Name.
  2. operation.Description = remarksoperation.Summary = remarks (line 382): All 9 snapshot files still use Description.
  3. operation.RequestBody.Description = description moved after examples block (line 479): All 9 snapshot files still have the old ordering with Description before the examples check.

Since these are verified snapshot files (used by the test framework to verify source generator output), having them out of sync with the actual emitter template means the tests will fail. Either the snapshots need to be regenerated, or these emitter changes should be reverted if they were unintended.

Was this helpful? React with 👍 / 👎

  • Apply suggested fix

Copy link

@gitar-bot-staging gitar-bot-staging bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ This PR is blocked due to unresolved code review findings.

Configure merge blocking · Maintainers can dismiss this review. Gitar never approves changes.

@gitar-bot-staging
Copy link

gitar-bot-staging bot commented Feb 10, 2026

Code Review ⚠️ Changes requested 0 resolved / 3 findings

The core null-check fix is correct, but three additional unrelated changes in the emitter template (remarks→Summary overwrite, metadata.Name→propertyName, RequestBody.Description reorder) were not reflected in the 9 snapshot verification files, causing test failures.

⚠️ Bug: Remarks now overwrites Summary instead of setting Description

📄 src/OpenApi/gen/XmlCommentGenerator.Emitter.cs:380-383

The change from operation.Description = remarks to operation.Summary = remarks (line 382) means that when both <summary> and <remarks> XML tags are present on a method, the remarks text will overwrite the summary that was just set on line 374.

Previously:

  • <summary>operation.Summary
  • <remarks>operation.Description

Now:

  • <summary>operation.Summary
  • <remarks>operation.Summary (overwrites the summary!)

This seems semantically incorrect. If both tags are provided, the summary is silently lost. The original behavior of mapping remarks to operation.Description makes more sense in the OpenAPI context, where Summary and Description are distinct fields.

Additionally, this change is NOT reflected in any of the 9 snapshot files (they all still have operation.Description = remarks), so the snapshot tests will fail when regenerated.

Suggested fix
                if (methodComment.Remarks is { } remarks)
                {
                    operation.Description = remarks;
                }
⚠️ Bug: Snapshot files not updated for propertyName and other changes

📄 src/OpenApi/gen/XmlCommentGenerator.Emitter.cs:452 📄 src/OpenApi/test/Microsoft.AspNetCore.OpenApi.SourceGenerators.Tests/snapshots/OperationTests.SupportsRouteParametersFromControllers#OpenApiXmlCommentSupport.generated.verified.cs

The emitter template has three changes beyond the null-check fix, but the snapshot verification files were only updated for the null-check. The other changes will cause snapshot test failures:

  1. p.Name == metadata.Namep.Name == propertyName (line 452): All 9 snapshot files still use metadata.Name.
  2. operation.Description = remarksoperation.Summary = remarks (line 382): All 9 snapshot files still use Description.
  3. operation.RequestBody.Description = description moved after examples block (line 479): All 9 snapshot files still have the old ordering with Description before the examples check.

Since these are verified snapshot files (used by the test framework to verify source generator output), having them out of sync with the actual emitter template means the tests will fail. Either the snapshots need to be regenerated, or these emitter changes should be reverted if they were unintended.

💡 Quality: License header removed from XmlCommentGenerator.Emitter.cs

📄 src/OpenApi/gen/XmlCommentGenerator.Emitter.cs:1

The MIT license header (// Licensed to the .NET Foundation under one or more agreements.) was removed from XmlCommentGenerator.Emitter.cs. Every other file in src/OpenApi/gen/ retains this header. This appears to be an accidental deletion — the diff shows the first 3 lines (the license comment block) were removed.

Suggested fix
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

using System.Collections.Generic;
Rules 🎸 2 actions taken

Gitar Rules

🎸 Linear Auto-Linking: Searched Linear for matching issues with 0% confidence - no relevant issues found in workspace (appears to track internal Gitar development, not external ASP.NET Core contributions)
🎸 Summary Enhancement: Appended 'Summary by Gitar' section with 3 technical bullet points explaining the null-check fix, regression test coverage, and backward compatibility

4 rules not applicable. Show all rules by commenting gitar display:verbose.

Options

Auto-apply is off → Gitar will not commit updates to this branch.
Display: compact → Showing less information.

Comment with these commands to change:

Auto-apply Compact
gitar auto-apply:on         
gitar display:verbose         

Was this helpful? React with 👍 / 👎 | Gitar

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants