Repository navigation
Refuse a null parameter, member or nested type before writing [patch] - #199
Merged
Merged
Conversation
A null entry in Parameters, PositionalParameters, Members or NestedClasses used to throw NullReferenceException partway through the declaration, leaving `void M}` or `record R` behind. Validate now rejects them up front with an InvalidOperationException naming the template and collection, and method, constructor and operator WriteTo run that check before writing. Fixes #198 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_017vfJW5L5j1hRifcohu2Dmb
Keeps both TemplateRendering helpers: EnsureNoNullEntries from this branch and NonBlank from #200. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_017vfJW5L5j1hRifcohu2Dmb
OperatorTemplate.Validate keeps #193's base.Validate() call alongside the null-parameter check. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_017vfJW5L5j1hRifcohu2Dmb
Follows #186's Validate(CodeBlocker) signature in the method, constructor and operator overrides, keeping the null-parameter check. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_017vfJW5L5j1hRifcohu2Dmb
|
This was referenced Nov 11, 2026
This was referenced Nov 12, 2026
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.



Fixes #198
What changed
A
nullentry in a template collection used to throwNullReferenceExceptionpartway through the declaration. The class body's scope then closed its brace onto the half-written line (void M},record R). The check now runs up front inValidate, before anything is written:ClassTemplate.Validaterejects a null entry inMembers,NestedClassesandPositionalParametersMethodTemplate,ConstructorTemplateandOperatorTemplategain aValidatethat rejects a nullParametersentry. TheirWriteTocalls it first, so writing a member on its own is also all-or-nothingTemplateRendering.EnsureNoNullEntries, and its message names the template and the collection (e.g.Method 'M' has a null entry in Parameters.)Notes for review
ArgumentException/ArgumentNullException. I usedInvalidOperationExceptionbecauseClassTemplate.WriteToalready documents it for "a member would be refused when written. Nothing is written", and every existingValidatefailure throws it. A null entry is template state rather than a method argument. If you preferArgumentException, it's a one-line change in the helper.DocTagentries are not covered here. Check a template's doc comment before writing the class that holds it [patch] #193 (for A class whose member has an invalid doc comment (a line break in a param/see-also name) is still written up to that member, then throws (#164 again, through DocComment) #188) moves doc-comment checks intoTemplateBase.Validate, and that's the right place to reject null tags. Adding them here would conflict with that PR.Tests
There are six new tests in
TemplateTests: a null method parameter (inside a class, and written on its own), a null positional parameter, a null constructor parameter, a null operator parameter, and a null member or nested class. Each asserts the exception and that the writer holds nothing new.Generated by Claude Code