Repository navigation
Fix SA1627/SA1651 crash on <include> with no documented member - #4380
Merged
Merged
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #4380 +/- ##
=======================================
Coverage 97.63% 97.63%
=======================================
Files 1345 1345
Lines 151674 151698 +24
Branches 5216 5218 +2
=======================================
+ Hits 148082 148106 +24
Misses 2268 2268
Partials 1324 1324 🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
🟢 Approval recommended
The narrow guards address the crash without changing nonempty-documentation analysis, and both affected analyzers have targeted regression tests.
No open issues 🎉
What changed in this PR
This PR prevents SA1627 and SA1651 from crashing when an orphaned <include> documentation comment produces empty expanded XML.
Changes:
- Skip XML parsing when expanded documentation is null or empty, preserving analysis of nonempty documentation.
- Add regression tests for both analyzers covering an include comment before an undocumented type’s closing brace.
| File | Description |
|---|---|
| test/StyleCop.Analyzers.Test/DocumentationRules/SA1651UnitTests.cs | Adds regression coverage for the SA1651 crash. |
| test/StyleCop.Analyzers.Test/DocumentationRules/SA1627UnitTests.cs | Adds regression coverage for the SA1627 crash. |
| src/StyleCop.Analyzers/DocumentationRules/SA1651DoNotUsePlaceholderElements.cs | Returns false before parsing empty documentation. |
| src/StyleCop.Analyzers/DocumentationRules/SA1627DocumentationTextMustNotBeEmpty.cs | Returns early before parsing empty documentation. |
Review effort: Balanced
This was referenced Nov 11, 2026
Bump StyleCop.Analyzers from 1.2.0-beta.556 to 1.3.180
microsoftgraph/aspnetcore-webhooks-sample#436
Open
Closed
This was referenced Nov 24, 2026
Open
Open
Closed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Found by the fuzz harness (
tools/StyleCop.Analyzers.Fuzz,mutatecampaigns with random seeds 2026/909/87109/95028 over the extracted-literal corpus).Bug: SA1627 and SA1651 throw
XmlException: Root element is missing(AD0001) when an<include>documentation comment is placed before the closing brace of an undocumented type (valid code; the compiler only reports CS1587). The expanded include documentation is empty, and it was passed straight toXElement.Parse.Fix: return early when the expanded documentation is null or empty.
Tests:
TestIncludedDocumentationBeforeCloseBraceOfUndocumentedTypeAsyncin SA1627UnitTests and SA1651UnitTests. Both failed with AD0001 before the fix.Analyzer cost: one
string.IsNullOrEmptycheck on a path that already parses XML. Negligible.