From: Stephen Toub Date: Fri, 22 Jul 2022 21:48:03 +0000 (-0400) Subject: Tighten nullable annotations on RegistryKey.GetValue (#72679) X-Git-Tag: accepted/tizen/unified/riscv/20231226.055536~7610 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=768500cfc05a742a5b9c73ad54645a3d8534564a;p=platform%2Fupstream%2Fdotnet%2Fruntime.git Tighten nullable annotations on RegistryKey.GetValue (#72679) * Tighten nullable annotations on RegistryKey.GetValue * Use nameof in attributes --- diff --git a/src/libraries/Microsoft.Win32.Registry/ref/Microsoft.Win32.Registry.cs b/src/libraries/Microsoft.Win32.Registry/ref/Microsoft.Win32.Registry.cs index 99acbd1..f92165d 100644 --- a/src/libraries/Microsoft.Win32.Registry/ref/Microsoft.Win32.Registry.cs +++ b/src/libraries/Microsoft.Win32.Registry/ref/Microsoft.Win32.Registry.cs @@ -57,7 +57,9 @@ namespace Microsoft.Win32 public System.Security.AccessControl.RegistrySecurity GetAccessControl(System.Security.AccessControl.AccessControlSections includeSections) { throw null; } public string[] GetSubKeyNames() { throw null; } public object? GetValue(string? name) { throw null; } + [return: System.Diagnostics.CodeAnalysis.NotNullIfNotNullAttribute("defaultValue")] public object? GetValue(string? name, object? defaultValue) { throw null; } + [return: System.Diagnostics.CodeAnalysis.NotNullIfNotNullAttribute("defaultValue")] public object? GetValue(string? name, object? defaultValue, Microsoft.Win32.RegistryValueOptions options) { throw null; } public Microsoft.Win32.RegistryValueKind GetValueKind(string? name) { throw null; } public string[] GetValueNames() { throw null; } diff --git a/src/libraries/Microsoft.Win32.Registry/src/Microsoft/Win32/RegistryKey.FileSystem.cs b/src/libraries/Microsoft.Win32.Registry/src/Microsoft/Win32/RegistryKey.FileSystem.cs index 3d4274c..f91463f 100644 --- a/src/libraries/Microsoft.Win32.Registry/src/Microsoft/Win32/RegistryKey.FileSystem.cs +++ b/src/libraries/Microsoft.Win32.Registry/src/Microsoft/Win32/RegistryKey.FileSystem.cs @@ -3,6 +3,7 @@ using Microsoft.Win32.SafeHandles; using System; +using System.Diagnostics.CodeAnalysis; namespace Microsoft.Win32 { @@ -91,6 +92,7 @@ namespace Microsoft.Win32 throw new PlatformNotSupportedException(SR.PlatformNotSupported_Registry); } + [return: NotNullIfNotNull(nameof(defaultValue))] private static object InternalGetValueCore(string? name, object? defaultValue, bool doNotExpand) { throw new PlatformNotSupportedException(SR.PlatformNotSupported_Registry); diff --git a/src/libraries/Microsoft.Win32.Registry/src/Microsoft/Win32/RegistryKey.Windows.cs b/src/libraries/Microsoft.Win32.Registry/src/Microsoft/Win32/RegistryKey.Windows.cs index c21cbb2..f3de353 100644 --- a/src/libraries/Microsoft.Win32.Registry/src/Microsoft/Win32/RegistryKey.Windows.cs +++ b/src/libraries/Microsoft.Win32.Registry/src/Microsoft/Win32/RegistryKey.Windows.cs @@ -6,6 +6,7 @@ using System; using System.Buffers; using System.Collections.Generic; using System.Diagnostics; +using System.Diagnostics.CodeAnalysis; using System.IO; using System.Security; @@ -528,6 +529,7 @@ namespace Microsoft.Win32 return names.ToArray(); } + [return: NotNullIfNotNull(nameof(defaultValue))] private object? InternalGetValueCore(string? name, object? defaultValue, bool doNotExpand) { object? data = defaultValue; diff --git a/src/libraries/Microsoft.Win32.Registry/src/Microsoft/Win32/RegistryKey.cs b/src/libraries/Microsoft.Win32.Registry/src/Microsoft/Win32/RegistryKey.cs index 233b7bf..8412bb5 100644 --- a/src/libraries/Microsoft.Win32.Registry/src/Microsoft/Win32/RegistryKey.cs +++ b/src/libraries/Microsoft.Win32.Registry/src/Microsoft/Win32/RegistryKey.cs @@ -509,11 +509,13 @@ namespace Microsoft.Win32 /// Name of value to retrieve. /// Value to return if name doesn't exist. /// The data associated with the value. + [return: NotNullIfNotNull(nameof(defaultValue))] public object? GetValue(string? name, object? defaultValue) { return InternalGetValue(name, defaultValue, false); } + [return: NotNullIfNotNull(nameof(defaultValue))] public object? GetValue(string? name, object? defaultValue, RegistryValueOptions options) { if (options < RegistryValueOptions.None || options > RegistryValueOptions.DoNotExpandEnvironmentNames) @@ -524,6 +526,7 @@ namespace Microsoft.Win32 return InternalGetValue(name, defaultValue, doNotExpand); } + [return: NotNullIfNotNull(nameof(defaultValue))] private object? InternalGetValue(string? name, object? defaultValue, bool doNotExpand) { EnsureNotDisposed();