Fix null-forgiving operator misuse in System.Diagnostics.EventLog#126639
Draft
Fix null-forgiving operator misuse in System.Diagnostics.EventLog#126639
Conversation
…LogInternal - Replace EventLog! with proper null guards in all TraceEvent/TraceData methods - Replace parent! with parent?. null-conditional in EnableRaisingEvents, SynchronizingObject, StartRaisingEvents, and StopRaisingEvents - Capture onEntryWrittenHandler to local variable in CompletionCallback to prevent potential TOCTOU race condition - Replace strings[i]! with local variable after null-coalescing assignment Agent-Logs-Url: https://github.com/dotnet/runtime/sessions/98985e7e-eb8b-4ef4-8b52-7b43d0c32b35 Co-authored-by: krwq <[email protected]>
Member
|
cc: @RenderMichael - note this PR is auto-generated |
Contributor
|
Tagging subscribers to this area: @steveisok, @dotnet/area-system-diagnostics-tracing |
tarekgh
reviewed
Apr 8, 2026
| private void StartRaisingEvents(string currentMachineName, string currentLogName) | ||
| { | ||
| if (!boolFlags[Flag_initializing] && !boolFlags[Flag_monitoring] && !parent!.ComponentDesignMode) | ||
| if (!boolFlags[Flag_initializing] && !boolFlags[Flag_monitoring] && parent?.ComponentDesignMode != true) |
Member
There was a problem hiding this comment.
should it be parent?.ComponentDesignMode == false? if parent is null, what parent?.ComponentDesignMode != true will result?
tarekgh
reviewed
Apr 8, 2026
| private void StopRaisingEvents(/*string currentMachineName,*/ string currentLogName) | ||
| { | ||
| if (!boolFlags[Flag_initializing] && boolFlags[Flag_monitoring] && !parent!.ComponentDesignMode) | ||
| if (!boolFlags[Flag_initializing] && boolFlags[Flag_monitoring] && parent?.ComponentDesignMode != true) |
Member
There was a problem hiding this comment.
I'll not comment more on similar issue
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.
Description
Follow-up to #119891 (NRT annotations for
System.Diagnostics.EventLog). Addresses unresolved review comments by replacing unsafe null-forgiving operator (!) usage with proper null checks where the nullable type is genuine.EventLogproperty isEventLog?but allTraceEvent/TraceDatamethods usedEventLog!.WriteEvent(...). Replaced with local capture + early return on null (6 sites).parent!:parentfield isEventLog?and genuinely null in static write paths and listener infrastructure. Replacedparent!.ComponentDesignModewithparent?.ComponentDesignMode == true(4 sites).onEntryWrittenHandlerfield was null-checked then accessed viathis.onEntryWrittenHandler— racy if unsubscribed between check and invocation. Captured to local.strings[i]!.Lengthafterstrings[i] ??= string.Empty— replaced withstring s = strings[i] ??= string.Empty; if (s.Length > ...)to eliminate the suppression.Suggested further improvements (separate PRs)
IEnumerable<string?>inner nullability in Reader APIs may be overly broad —EvtVarTypeNullmay be the only null variantEventRecord.FormatDescription(IEnumerable<object>? values)accepts null but a parameterless overload existsEventRecordWrittenEventArgsconstructors could unify null handlingLogListeningInfofields could bereadonly