From: Santiago Fernandez Madero Date: Fri, 7 Jun 2019 16:01:51 +0000 (-0500) Subject: Address nullable feedback for System.Runtime and System.Runtime.Extensions (#25017) X-Git-Tag: accepted/tizen/unified/20190813.215958~40^2~238 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=b51993933c5f2f29b20d229cdb32bbcb41e76dd6;p=platform%2Fupstream%2Fcoreclr.git Address nullable feedback for System.Runtime and System.Runtime.Extensions (#25017) * Address last nullable feedback from System.Runtime * Address nullable feedback for System.Runtime.Extensions * PR Feedback --- diff --git a/src/System.Private.CoreLib/shared/System/Collections/Generic/Dictionary.cs b/src/System.Private.CoreLib/shared/System/Collections/Generic/Dictionary.cs index d79924c..890b279 100644 --- a/src/System.Private.CoreLib/shared/System/Collections/Generic/Dictionary.cs +++ b/src/System.Private.CoreLib/shared/System/Collections/Generic/Dictionary.cs @@ -673,7 +673,7 @@ namespace System.Collections.Generic return true; } - public virtual void OnDeserialization(object sender) + public virtual void OnDeserialization(object? sender) { HashHelpers.SerializationInfoTable.TryGetValue(this, out SerializationInfo siInfo); diff --git a/src/System.Private.CoreLib/shared/System/Collections/Hashtable.cs b/src/System.Private.CoreLib/shared/System/Collections/Hashtable.cs index 06e57b7..f5a90e6 100644 --- a/src/System.Private.CoreLib/shared/System/Collections/Hashtable.cs +++ b/src/System.Private.CoreLib/shared/System/Collections/Hashtable.cs @@ -1153,7 +1153,7 @@ namespace System.Collections // // DeserializationEvent Listener // - public virtual void OnDeserialization(object sender) + public virtual void OnDeserialization(object? sender) { if (_buckets != null) { @@ -1491,7 +1491,7 @@ namespace System.Collections } } - public override void OnDeserialization(object sender) + public override void OnDeserialization(object? sender) { // Does nothing. We have to implement this because our parent HT implements it, // but it doesn't do anything meaningful. The real work will be done when we diff --git a/src/System.Private.CoreLib/shared/System/DateTimeOffset.cs b/src/System.Private.CoreLib/shared/System/DateTimeOffset.cs index e328726..2045702 100644 --- a/src/System.Private.CoreLib/shared/System/DateTimeOffset.cs +++ b/src/System.Private.CoreLib/shared/System/DateTimeOffset.cs @@ -591,7 +591,7 @@ namespace System // ----- SECTION: private serialization instance methods ----------------* - void IDeserializationCallback.OnDeserialization(object sender) + void IDeserializationCallback.OnDeserialization(object? sender) { try { diff --git a/src/System.Private.CoreLib/shared/System/Decimal.cs b/src/System.Private.CoreLib/shared/System/Decimal.cs index 72ac754..47bea85 100644 --- a/src/System.Private.CoreLib/shared/System/Decimal.cs +++ b/src/System.Private.CoreLib/shared/System/Decimal.cs @@ -276,7 +276,7 @@ namespace System flags |= SignMask; } - void IDeserializationCallback.OnDeserialization(object sender) + void IDeserializationCallback.OnDeserialization(object? sender) { // OnDeserialization is called after each instance of this class is deserialized. // This callback method performs decimal validation after being deserialized. diff --git a/src/System.Private.CoreLib/shared/System/Globalization/CompareInfo.cs b/src/System.Private.CoreLib/shared/System/Globalization/CompareInfo.cs index dd4da0d..03e1302 100644 --- a/src/System.Private.CoreLib/shared/System/Globalization/CompareInfo.cs +++ b/src/System.Private.CoreLib/shared/System/Globalization/CompareInfo.cs @@ -175,7 +175,7 @@ namespace System.Globalization m_name = null!; } - void IDeserializationCallback.OnDeserialization(object sender) + void IDeserializationCallback.OnDeserialization(object? sender) { OnDeserialized(); } diff --git a/src/System.Private.CoreLib/shared/System/Globalization/TextInfo.cs b/src/System.Private.CoreLib/shared/System/Globalization/TextInfo.cs index 38005a0..e5553f7 100644 --- a/src/System.Private.CoreLib/shared/System/Globalization/TextInfo.cs +++ b/src/System.Private.CoreLib/shared/System/Globalization/TextInfo.cs @@ -63,7 +63,7 @@ namespace System.Globalization FinishInitialization(); } - void IDeserializationCallback.OnDeserialization(object sender) + void IDeserializationCallback.OnDeserialization(object? sender) { throw new PlatformNotSupportedException(); } diff --git a/src/System.Private.CoreLib/shared/System/Reflection/AssemblyName.cs b/src/System.Private.CoreLib/shared/System/Reflection/AssemblyName.cs index 3de53a1..0687dcf 100644 --- a/src/System.Private.CoreLib/shared/System/Reflection/AssemblyName.cs +++ b/src/System.Private.CoreLib/shared/System/Reflection/AssemblyName.cs @@ -245,7 +245,7 @@ namespace System.Reflection throw new PlatformNotSupportedException(); } - public void OnDeserialization(object sender) + public void OnDeserialization(object? sender) { throw new PlatformNotSupportedException(); } diff --git a/src/System.Private.CoreLib/shared/System/Reflection/StrongNameKeyPair.cs b/src/System.Private.CoreLib/shared/System/Reflection/StrongNameKeyPair.cs index a0ba97f..52fa614 100644 --- a/src/System.Private.CoreLib/shared/System/Reflection/StrongNameKeyPair.cs +++ b/src/System.Private.CoreLib/shared/System/Reflection/StrongNameKeyPair.cs @@ -50,7 +50,7 @@ namespace System.Reflection throw new PlatformNotSupportedException(); } - void IDeserializationCallback.OnDeserialization(object sender) + void IDeserializationCallback.OnDeserialization(object? sender) { throw new PlatformNotSupportedException(); } diff --git a/src/System.Private.CoreLib/shared/System/ResolveEventHandler.cs b/src/System.Private.CoreLib/shared/System/ResolveEventHandler.cs index 7cb2818..a08be72 100644 --- a/src/System.Private.CoreLib/shared/System/ResolveEventHandler.cs +++ b/src/System.Private.CoreLib/shared/System/ResolveEventHandler.cs @@ -6,5 +6,5 @@ using System.Reflection; namespace System { - public delegate Assembly ResolveEventHandler(object? sender, ResolveEventArgs args); + public delegate Assembly? ResolveEventHandler(object? sender, ResolveEventArgs args); } diff --git a/src/System.Private.CoreLib/shared/System/Runtime/Serialization/IDeserializationCallback.cs b/src/System.Private.CoreLib/shared/System/Runtime/Serialization/IDeserializationCallback.cs index a1c1671..22b799c 100644 --- a/src/System.Private.CoreLib/shared/System/Runtime/Serialization/IDeserializationCallback.cs +++ b/src/System.Private.CoreLib/shared/System/Runtime/Serialization/IDeserializationCallback.cs @@ -6,6 +6,6 @@ namespace System.Runtime.Serialization { public interface IDeserializationCallback { - void OnDeserialization(object sender); + void OnDeserialization(object? sender); } } diff --git a/src/System.Private.CoreLib/shared/System/Security/PermissionSet.cs b/src/System.Private.CoreLib/shared/System/Security/PermissionSet.cs index 7d1327d..999d039 100644 --- a/src/System.Private.CoreLib/shared/System/Security/PermissionSet.cs +++ b/src/System.Private.CoreLib/shared/System/Security/PermissionSet.cs @@ -48,7 +48,7 @@ namespace System.Security public static void RevertAssert() { } public IPermission? SetPermission(IPermission? perm) { return SetPermissionImpl(perm); } protected virtual IPermission? SetPermissionImpl(IPermission? perm) { return default(IPermission); } - void IDeserializationCallback.OnDeserialization(object sender) { } + void IDeserializationCallback.OnDeserialization(object? sender) { } public override string ToString() => base.ToString()!; public virtual SecurityElement? ToXml() { return default(SecurityElement); } public PermissionSet? Union(PermissionSet? other) { return default(PermissionSet); } diff --git a/src/System.Private.CoreLib/shared/System/Text/CodePageDataItem.cs b/src/System.Private.CoreLib/shared/System/Text/CodePageDataItem.cs index e2be2e3..e4b8d4d 100644 --- a/src/System.Private.CoreLib/shared/System/Text/CodePageDataItem.cs +++ b/src/System.Private.CoreLib/shared/System/Text/CodePageDataItem.cs @@ -8,19 +8,19 @@ namespace System.Text { public int CodePage { get; } public int UIFamilyCodePage { get; } - public string? WebName { get; } - public string? HeaderName { get; } - public string? BodyName { get; } - public string? DisplayName { get; } + public string WebName { get; } + public string HeaderName { get; } + public string BodyName { get; } + public string DisplayName { get; } public uint Flags { get; } internal CodePageDataItem( int codePage, int uiFamilyCodePage, - string? webName, - string? headerName, - string? bodyName, - string? displayName, + string webName, + string headerName, + string bodyName, + string displayName, uint flags) { CodePage = codePage; diff --git a/src/System.Private.CoreLib/shared/System/Text/Encoding.cs b/src/System.Private.CoreLib/shared/System/Text/Encoding.cs index a1180a1..74f0b95 100644 --- a/src/System.Private.CoreLib/shared/System/Text/Encoding.cs +++ b/src/System.Private.CoreLib/shared/System/Text/Encoding.cs @@ -370,7 +370,7 @@ namespace System.Text // Returns the name for this encoding that can be used with mail agent body tags. // If the encoding may not be used, the string is empty. - public virtual string? BodyName + public virtual string BodyName { get { @@ -383,7 +383,7 @@ namespace System.Text } // Returns the human-readable description of the encoding ( e.g. Hebrew (DOS)). - public virtual string? EncodingName + public virtual string EncodingName { get { @@ -399,7 +399,7 @@ namespace System.Text // Returns the name for this encoding that can be used with mail agent header // tags. If the encoding may not be used, the string is empty. - public virtual string? HeaderName + public virtual string HeaderName { get { @@ -412,7 +412,7 @@ namespace System.Text } // Returns the IANA preferred name for this encoding. - public virtual string? WebName + public virtual string WebName { get { diff --git a/src/System.Private.CoreLib/shared/System/Text/StringBuilder.cs b/src/System.Private.CoreLib/shared/System/Text/StringBuilder.cs index 225442c..165ea4e 100644 --- a/src/System.Private.CoreLib/shared/System/Text/StringBuilder.cs +++ b/src/System.Private.CoreLib/shared/System/Text/StringBuilder.cs @@ -1520,13 +1520,13 @@ namespace System.Text return AppendFormatHelper(null, format, new ParamsArray(args)); } - public StringBuilder AppendFormat(IFormatProvider provider, string format, object? arg0) => AppendFormatHelper(provider, format, new ParamsArray(arg0)); + public StringBuilder AppendFormat(IFormatProvider? provider, string format, object? arg0) => AppendFormatHelper(provider, format, new ParamsArray(arg0)); - public StringBuilder AppendFormat(IFormatProvider provider, string format, object? arg0, object? arg1) => AppendFormatHelper(provider, format, new ParamsArray(arg0, arg1)); + public StringBuilder AppendFormat(IFormatProvider? provider, string format, object? arg0, object? arg1) => AppendFormatHelper(provider, format, new ParamsArray(arg0, arg1)); - public StringBuilder AppendFormat(IFormatProvider provider, string format, object? arg0, object? arg1, object? arg2) => AppendFormatHelper(provider, format, new ParamsArray(arg0, arg1, arg2)); + public StringBuilder AppendFormat(IFormatProvider? provider, string format, object? arg0, object? arg1, object? arg2) => AppendFormatHelper(provider, format, new ParamsArray(arg0, arg1, arg2)); - public StringBuilder AppendFormat(IFormatProvider provider, string format, params object?[] args) + public StringBuilder AppendFormat(IFormatProvider? provider, string format, params object?[] args) { if (args == null) { diff --git a/src/System.Private.CoreLib/shared/System/TimeZoneInfo.AdjustmentRule.cs b/src/System.Private.CoreLib/shared/System/TimeZoneInfo.AdjustmentRule.cs index a3ffb1c..e2e5188 100644 --- a/src/System.Private.CoreLib/shared/System/TimeZoneInfo.AdjustmentRule.cs +++ b/src/System.Private.CoreLib/shared/System/TimeZoneInfo.AdjustmentRule.cs @@ -211,7 +211,7 @@ namespace System "DaylightDelta should not ever be more than 24h"); } - void IDeserializationCallback.OnDeserialization(object sender) + void IDeserializationCallback.OnDeserialization(object? sender) { // OnDeserialization is called after each instance of this class is deserialized. // This callback method performs AdjustmentRule validation after being deserialized. diff --git a/src/System.Private.CoreLib/shared/System/TimeZoneInfo.TransitionTime.cs b/src/System.Private.CoreLib/shared/System/TimeZoneInfo.TransitionTime.cs index 4b0abe8..aa88a14 100644 --- a/src/System.Private.CoreLib/shared/System/TimeZoneInfo.TransitionTime.cs +++ b/src/System.Private.CoreLib/shared/System/TimeZoneInfo.TransitionTime.cs @@ -106,7 +106,7 @@ namespace System } } - void IDeserializationCallback.OnDeserialization(object sender) + void IDeserializationCallback.OnDeserialization(object? sender) { // OnDeserialization is called after each instance of this class is deserialized. // This callback method performs TransitionTime validation after being deserialized. diff --git a/src/System.Private.CoreLib/shared/System/TimeZoneInfo.cs b/src/System.Private.CoreLib/shared/System/TimeZoneInfo.cs index 768385c..589a605 100644 --- a/src/System.Private.CoreLib/shared/System/TimeZoneInfo.cs +++ b/src/System.Private.CoreLib/shared/System/TimeZoneInfo.cs @@ -1005,7 +1005,7 @@ namespace System disableDaylightSavingTime); } - void IDeserializationCallback.OnDeserialization(object sender) + void IDeserializationCallback.OnDeserialization(object? sender) { try { diff --git a/src/System.Private.CoreLib/src/System/Environment.CoreCLR.cs b/src/System.Private.CoreLib/src/System/Environment.CoreCLR.cs index b2d7f11..a296a1c 100644 --- a/src/System.Private.CoreLib/src/System/Environment.CoreCLR.cs +++ b/src/System.Private.CoreLib/src/System/Environment.CoreCLR.cs @@ -20,6 +20,7 @@ namespace System [DllImport(JitHelpers.QCall, CharSet = CharSet.Unicode)] private static extern void _Exit(int exitCode); + [DoesNotReturn] public static void Exit(int exitCode) => _Exit(exitCode); public static extern int ExitCode diff --git a/src/System.Private.CoreLib/src/System/Runtime/CompilerServices/RuntimeHelpers.cs b/src/System.Private.CoreLib/src/System/Runtime/CompilerServices/RuntimeHelpers.cs index 1c36377..9047f5e 100644 --- a/src/System.Private.CoreLib/src/System/Runtime/CompilerServices/RuntimeHelpers.cs +++ b/src/System.Private.CoreLib/src/System/Runtime/CompilerServices/RuntimeHelpers.cs @@ -3,6 +3,7 @@ // See the LICENSE file in the project root for more information. using System.Diagnostics; +using System.Diagnostics.CodeAnalysis; using System.Runtime.InteropServices; using Internal.Runtime.CompilerServices; @@ -27,7 +28,8 @@ namespace System.Runtime.CompilerServices // Of course, reference types are not cloned. // [MethodImplAttribute(MethodImplOptions.InternalCall)] - public static extern object GetObjectValue(object obj); + [return: NotNullIfNotNull("obj")] + public static extern object? GetObjectValue(object? obj); // RunClassConstructor causes the class constructor for the given type to be triggered // in the current domain. After this call returns, the class constructor is guaranteed to diff --git a/src/System.Private.CoreLib/src/System/Runtime/Loader/AssemblyLoadContext.CoreCLR.cs b/src/System.Private.CoreLib/src/System/Runtime/Loader/AssemblyLoadContext.CoreCLR.cs index 197a07e..bd56e50 100644 --- a/src/System.Private.CoreLib/src/System/Runtime/Loader/AssemblyLoadContext.CoreCLR.cs +++ b/src/System.Private.CoreLib/src/System/Runtime/Loader/AssemblyLoadContext.CoreCLR.cs @@ -328,7 +328,7 @@ namespace System.Runtime.Loader foreach (ResolveEventHandler handler in eventHandler.GetInvocationList()) { - Assembly asm = handler(null /* AppDomain */, args); + Assembly? asm = handler(null /* AppDomain */, args); RuntimeAssembly? ret = GetRuntimeAssembly(asm); if (ret != null) return ret; @@ -337,7 +337,7 @@ namespace System.Runtime.Loader return null; } - private static RuntimeAssembly? GetRuntimeAssembly(Assembly asm) + private static RuntimeAssembly? GetRuntimeAssembly(Assembly? asm) { return asm == null ? null :