Skip to content

Commit 18290ad

Browse files
RenderMichaelkrwq
andauthored
Annotate System.Diagnostics.EventLog with Nullable Reference Types (#119891)
Contributes to #90400 --------- Co-authored-by: Krzysztof Wicher <kwicher@microsoft.com>
1 parent ddc9174 commit 18290ad

37 files changed

Lines changed: 725 additions & 676 deletions

src/libraries/Common/src/Interop/Windows/Advapi32/Interop.ClearEventLog.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,6 @@ internal static partial class Advapi32
1010
{
1111
[LibraryImport(Libraries.Advapi32, EntryPoint = "ClearEventLogW", SetLastError = true, StringMarshalling = StringMarshalling.Utf16)]
1212
[return: MarshalAs(UnmanagedType.Bool)]
13-
public static partial bool ClearEventLog(SafeEventLogReadHandle hEventLog, string lpBackupFileName);
13+
public static partial bool ClearEventLog(SafeEventLogReadHandle hEventLog, string? lpBackupFileName);
1414
}
1515
}

src/libraries/Common/src/Interop/Windows/Advapi32/Interop.ReportEvent.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ public static partial bool ReportEvent(
1616
short wType,
1717
ushort wcategory,
1818
uint dwEventID,
19-
byte[] lpUserSid,
19+
byte[]? lpUserSid,
2020
short wNumStrings,
2121
int dwDataSize,
2222
IntPtr lpStrings,

src/libraries/Common/src/System/Diagnostics/NetFrameworkUtils.cs

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,13 @@ namespace System.Diagnostics
1414
{
1515
internal static partial class NetFrameworkUtils
1616
{
17-
internal static void EnterMutex(string name, ref Mutex mutex)
17+
internal static void EnterMutex(string name, ref Mutex? mutex)
1818
{
1919
string mutexName = "Global\\" + name;
2020
EnterMutexWithoutGlobal(mutexName, ref mutex);
2121
}
2222

23-
internal static void EnterMutexWithoutGlobal(string mutexName, ref Mutex mutex)
23+
internal static void EnterMutexWithoutGlobal(string mutexName, ref Mutex? mutex)
2424
{
2525
Mutex tmpMutex = new Mutex(false, mutexName, out bool createdNew);
2626

@@ -47,7 +47,7 @@ internal static void EnterMutexWithoutGlobal(string mutexName, ref Mutex mutex)
4747
// just to allow us to poll for abort). A limitation of CERs in Whidbey (and part of the problem that put us in this
4848
// position in the first place) is that a CER root in a method will cause the entire method to delay thread aborts. So we
4949
// need to carefully partition the real CER part of out logic in a sub-method (and ensure the jit doesn't inline on us).
50-
private static bool SafeWaitForMutex(Mutex mutexIn, ref Mutex mutexOut)
50+
private static bool SafeWaitForMutex(Mutex mutexIn, ref Mutex? mutexOut)
5151
{
5252
Debug.Assert(mutexOut == null, "You must pass in a null ref Mutex");
5353

@@ -71,7 +71,7 @@ private static bool SafeWaitForMutex(Mutex mutexIn, ref Mutex mutexOut)
7171
// The portion of SafeWaitForMutex that runs under a CER and thus must not block for a arbitrary period of time.
7272
// This method must not be inlined (to stop the CER accidently spilling into the calling method).
7373
[MethodImplAttribute(MethodImplOptions.NoInlining)]
74-
private static bool SafeWaitForMutexOnce(Mutex mutexIn, ref Mutex mutexOut)
74+
private static bool SafeWaitForMutexOnce(Mutex mutexIn, ref Mutex? mutexOut)
7575
{
7676
bool ret;
7777

@@ -120,8 +120,8 @@ private static bool SafeWaitForMutexOnce(Mutex mutexIn, ref Mutex mutexOut)
120120
internal static string GetLatestBuildDllDirectory(string machineName)
121121
{
122122
string dllDir = "";
123-
RegistryKey baseKey = null;
124-
RegistryKey complusReg = null;
123+
RegistryKey? baseKey = null;
124+
RegistryKey? complusReg = null;
125125

126126
try
127127
{
@@ -136,25 +136,25 @@ internal static string GetLatestBuildDllDirectory(string machineName)
136136
complusReg = baseKey.OpenSubKey("SOFTWARE\\Microsoft\\.NETFramework");
137137
if (complusReg != null)
138138
{
139-
string installRoot = (string)complusReg.GetValue("InstallRoot");
139+
string? installRoot = (string?)complusReg.GetValue("InstallRoot");
140140
if (installRoot != null && installRoot != string.Empty)
141141
{
142142
// the "policy" subkey contains a v{major}.{minor} subkey for each version installed. There are also
143143
// some extra subkeys like "standards" and "upgrades" we want to ignore.
144144

145145
// first we figure out what version we are...
146146
string versionPrefix = "v" + Environment.Version.Major + "." + Environment.Version.Minor;
147-
RegistryKey policyKey = complusReg.OpenSubKey("policy");
147+
RegistryKey? policyKey = complusReg.OpenSubKey("policy");
148148

149149
// This is the full version string of the install on the remote machine we want to use (for example "v2.0.50727")
150-
string version = null;
150+
string? version = null;
151151

152152
if (policyKey != null)
153153
{
154154
try
155155
{
156156
// First check to see if there is a version of the runtime with the same minor and major number:
157-
RegistryKey bestKey = policyKey.OpenSubKey(versionPrefix);
157+
RegistryKey? bestKey = policyKey.OpenSubKey(versionPrefix);
158158

159159
if (bestKey != null)
160160
{
@@ -194,7 +194,7 @@ internal static string GetLatestBuildDllDirectory(string machineName)
194194
continue;
195195
}
196196

197-
RegistryKey k = policyKey.OpenSubKey(majorVersion);
197+
RegistryKey? k = policyKey.OpenSubKey(majorVersion);
198198
if (k == null)
199199
{
200200
// We may be able to use another subkey

0 commit comments

Comments
 (0)