Annotate System.Diagnostics.EventLog with Nullable Reference Types#119891
Annotate System.Diagnostics.EventLog with Nullable Reference Types#119891krwq merged 11 commits intodotnet:mainfrom
System.Diagnostics.EventLog with Nullable Reference Types#119891Conversation
src/libraries/System.Diagnostics.EventLog/src/System/Diagnostics/EventLog.cs
Show resolved
Hide resolved
src/libraries/System.Diagnostics.EventLog/src/System/Diagnostics/EventLog.cs
Show resolved
Hide resolved
src/libraries/System.Diagnostics.EventLog/src/System/Diagnostics/EventLog.cs
Show resolved
Hide resolved
src/libraries/System.Diagnostics.EventLog/src/System/Diagnostics/EventLogInternal.cs
Outdated
Show resolved
Hide resolved
src/libraries/System.Diagnostics.EventLog/src/System/Diagnostics/EventLogInternal.cs
Outdated
Show resolved
Hide resolved
src/libraries/System.Diagnostics.EventLog/src/System/Diagnostics/EventLogInternal.cs
Outdated
Show resolved
Hide resolved
src/libraries/System.Diagnostics.EventLog/src/System/Diagnostics/EventLogInternal.cs
Show resolved
Hide resolved
src/libraries/System.Diagnostics.EventLog/src/System/Diagnostics/EventLogInternal.cs
Outdated
Show resolved
Hide resolved
src/libraries/System.Diagnostics.EventLog/src/System/Diagnostics/EventLogInternal.cs
Show resolved
Hide resolved
src/libraries/System.Diagnostics.EventLog/src/System/Diagnostics/EventLogInternal.cs
Show resolved
Hide resolved
src/libraries/System.Diagnostics.EventLog/src/System/Diagnostics/EventLogInternal.cs
Show resolved
Hide resolved
src/libraries/System.Diagnostics.EventLog/src/System/Diagnostics/EventLogInternal.cs
Outdated
Show resolved
Hide resolved
src/libraries/System.Diagnostics.EventLog/src/System/Diagnostics/EventLogInternal.cs
Show resolved
Hide resolved
src/libraries/System.Diagnostics.EventLog/src/System/Diagnostics/EventLogInternal.cs
Show resolved
Hide resolved
src/libraries/System.Diagnostics.EventLog/src/System/Diagnostics/EventLogInternal.cs
Show resolved
Hide resolved
There was a problem hiding this comment.
Pull request overview
This PR enables Nullable Reference Types (NRT) annotations for the System.Diagnostics.EventLog library, contributing to issue #90400. The changes ensure that the codebase correctly expresses nullability intent through type annotations, improving type safety and reducing potential null reference exceptions.
Changes:
- Added nullable annotations (
?) to parameters, return types, fields, and properties across the library where null values are possible - Added
[NotNullWhen]attributes to improve flow analysis for null checks - Added
[MemberNotNull]and[MemberNotNullWhen]attributes to help the compiler understand null-state after certain operations - Removed
<Nullable>disable</Nullable>from project files to enable nullable reference type checking - Updated struct initialization to use constructor patterns instead of object initializers where appropriate
Reviewed changes
Copilot reviewed 37 out of 37 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| System.Diagnostics.EventLog.csproj | Enabled nullable reference types by removing disable directive |
| Messages/System.Diagnostics.EventLog.Messages.csproj | Removed nullable disable directive |
| ref/System.Diagnostics.EventLog.csproj | Removed nullable disable directive from reference assembly |
| ref/System.Diagnostics.EventLog.cs | Updated API signatures with nullable annotations |
| UnsafeNativeMethods.cs | Added nullable annotations to P/Invoke signatures and struct fields |
| EventLog.cs, EventLogInternal.cs | Added nullable annotations to public and internal APIs |
| EventLogEntry.cs, EventLogRecord.cs | Added nullable annotations to entry/record properties |
| EventLogReader.cs, EventLogWatcher.cs | Added nullable annotations to reader/watcher APIs |
| Various Reader classes | Added nullable annotations throughout event reader infrastructure |
| NetFrameworkUtils.cs | Added nullable annotations to utility methods |
| Interop files | Added nullable annotations to interop declarations |
src/libraries/System.Diagnostics.EventLog/src/System/Diagnostics/EventLogInternal.cs
Outdated
Show resolved
Hide resolved
src/libraries/System.Diagnostics.EventLog/src/System/Diagnostics/EventLog.cs
Show resolved
Hide resolved
src/libraries/System.Diagnostics.EventLog/src/System/Diagnostics/EventLogInternal.cs
Show resolved
Hide resolved
src/libraries/System.Diagnostics.EventLog/src/System/Diagnostics/Reader/EventKeyword.cs
Show resolved
Hide resolved
src/libraries/System.Diagnostics.EventLog/src/System/Diagnostics/Reader/EventLevel.cs
Show resolved
Hide resolved
...libraries/System.Diagnostics.EventLog/src/System/Diagnostics/Reader/EventLogConfiguration.cs
Outdated
Show resolved
Hide resolved
src/libraries/System.Diagnostics.EventLog/src/System/Diagnostics/Reader/EventLogLink.cs
Show resolved
Hide resolved
src/libraries/System.Diagnostics.EventLog/src/System/Diagnostics/Reader/EventLogQuery.cs
Outdated
Show resolved
Hide resolved
src/libraries/System.Diagnostics.EventLog/src/System/Diagnostics/Reader/EventLogReader.cs
Show resolved
Hide resolved
src/libraries/System.Diagnostics.EventLog/src/System/Diagnostics/Reader/EventLogRecord.cs
Show resolved
Hide resolved
src/libraries/System.Diagnostics.EventLog/src/System/Diagnostics/Reader/EventLogRecord.cs
Show resolved
Hide resolved
src/libraries/System.Diagnostics.EventLog/src/System/Diagnostics/Reader/EventLogRecord.cs
Show resolved
Hide resolved
src/libraries/System.Diagnostics.EventLog/src/System/Diagnostics/Reader/EventLogRecord.cs
Show resolved
Hide resolved
d7624f5 to
7d73f4d
Compare
|
The error seem like they are already reported in those two issues: |
|
/ba-g The errors are already reported in the issues mentioned above |
|
@RenderMichael please resolve/fix the comments to move this forward, CI is currently blocking on that. My biggest concerns are:
|
|
@RenderMichael are you still planning to continue with this PR? thanks! |
|
This PR is on my short list to cycle back to. |
Mapped from dotnet/runtime PR #119891 head commit 7d73f4dc007 onto standalone EventLog repo for apples-to-apples comparison with agent branches. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
|
We have a "skill" for null reference annotation in the new dotnet/skills repo. If you're using Copilot CLI (or Claude Code I think) you introduce it like this I tried an experiment, comparing your work here, with using Copilot to do the work without a skill, and using Copilot with a skill. Here's the writeup -- https://gist.github.com/danmoseley/2bd583fb655c9248828c0f8b339ac6c2 |
|
Updated gist above with two more experiments, using a more streamlined skill. Outcome -- a skill slimmer than the one in dotnet/skills currently would likely work better. But, no version was successfully adding the NRT attributes: too much cross-method analysis, apparently. Seems the "fastest" workflow for changes like this would be to use AI, hopefully with the optimized skill (about 30 mins) then go through, add attributes and review the annotations it made. Likely this would be much quicker than doing it 100% human. any thoughts welcome - hope you don't mind me piggy backing on your PR here |
src/libraries/System.Diagnostics.EventLog/src/System/Diagnostics/EventSourceCreationData.cs
Show resolved
Hide resolved
src/libraries/System.Diagnostics.EventLog/src/System/Diagnostics/Reader/EventLogSession.cs
Show resolved
Hide resolved
src/libraries/System.Diagnostics.EventLog/src/System/Diagnostics/EventLogTraceListener.cs
Show resolved
Hide resolved
...libraries/System.Diagnostics.EventLog/src/System/Diagnostics/Reader/EventLogConfiguration.cs
Show resolved
Hide resolved
src/libraries/System.Diagnostics.EventLog/src/System/Diagnostics/EventLogInternal.cs
Show resolved
Hide resolved
src/libraries/System.Diagnostics.EventLog/src/System/Diagnostics/Reader/EventLogReader.cs
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 37 out of 37 changed files in this pull request and generated 5 comments.
Comments suppressed due to low confidence (1)
src/libraries/System.Diagnostics.EventLog/ref/System.Diagnostics.EventLog.cs:400
- In the ref assembly,
EventLogSession.ExportLog*still requires a non-nullablestring query(andExportLogAndMessagesrequires non-nullableCultureInfo), but the implementation now accepts a nullable query (and nullableCultureInfo). Please update the ref nullable annotations to match the implementation so the public surface is consistent.
public void ClearLog(string logName, string? backupPath) { }
public void Dispose() { }
protected virtual void Dispose(bool disposing) { }
public void ExportLog(string path, System.Diagnostics.Eventing.Reader.PathType pathType, string query, string targetFilePath) { }
public void ExportLog(string path, System.Diagnostics.Eventing.Reader.PathType pathType, string query, string targetFilePath, bool tolerateQueryErrors) { }
public void ExportLogAndMessages(string path, System.Diagnostics.Eventing.Reader.PathType pathType, string query, string targetFilePath) { }
public void ExportLogAndMessages(string path, System.Diagnostics.Eventing.Reader.PathType pathType, string query, string targetFilePath, bool tolerateQueryErrors, System.Globalization.CultureInfo targetCultureInfo) { }
src/libraries/System.Diagnostics.EventLog/ref/System.Diagnostics.EventLog.cs
Show resolved
Hide resolved
src/libraries/System.Diagnostics.EventLog/ref/System.Diagnostics.EventLog.cs
Show resolved
Hide resolved
src/libraries/System.Diagnostics.EventLog/ref/System.Diagnostics.EventLog.cs
Outdated
Show resolved
Hide resolved
src/libraries/System.Diagnostics.EventLog/src/System/Diagnostics/EventLogTraceListener.cs
Show resolved
Hide resolved
src/libraries/System.Diagnostics.EventLog/src/System/Diagnostics/EventLogInternal.cs
Show resolved
Hide resolved
|
@RenderMichael I've addressed my main piece of feedback and pushed to your branch |
krwq
left a comment
There was a problem hiding this comment.
Any suggested product changes should be made separately for better visibility.
|
I've merged this as is as it's in acceptable state, we can iterate and improve further on this but that's also true to any other area |
|
I've started copilot session to try to further iterate on all skipped product changes here. I'll post it if it looks reasonable |
|
And thanks @RenderMichael for all the work here! |
Contributes to #90400