You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
A null DefaultValue with DefaultValueIsQuoted = true throws NullReferenceException mid-declaration and leaves void M} #209
When DefaultValueIsQuoted is set, TemplateBase.HasDefaultValue (CodeBlocker/Templates/TemplateBase.cs:41) is true whatever the value, so WriteDefaultValueTo (:108-119) calls TemplateRendering.QuoteStringLiteral(DefaultValue). That method dereferences value.Length at TemplateRendering.cs:144, so a null value throws a NullReferenceException. By then the declaration is already partly written.
An unquoted null DefaultValue is accepted and treated as "no initialiser". The quoted path is the only one that crashes.
NullReferenceException: Object reference not set to an instance of an object.
class C
{
void M}
A field or property with a quoted null default fails the same way.
Why it matters
A generator that maps an optional string from data, for example DefaultValue = attribute?.Value, DefaultValueIsQuoted = true, gets a bare NullReferenceException and a corrupt half-written class. It gets neither "" nor an up-front refusal. #198/#199 fixed this same symptom for null parameters and members, and DefaultValue's docs already say an empty quoted value writes "".
Activity