Address nullable feedback for System.Runtime and System.Runtime.Extensions (#25017)
authorSantiago Fernandez Madero <safern@microsoft.com>
Fri, 7 Jun 2019 16:01:51 +0000 (11:01 -0500)
committerStephen Toub <stoub@microsoft.com>
Fri, 7 Jun 2019 16:01:51 +0000 (12:01 -0400)
* Address last nullable feedback from System.Runtime

* Address nullable feedback for System.Runtime.Extensions

* PR Feedback

20 files changed:
src/System.Private.CoreLib/shared/System/Collections/Generic/Dictionary.cs
src/System.Private.CoreLib/shared/System/Collections/Hashtable.cs
src/System.Private.CoreLib/shared/System/DateTimeOffset.cs
src/System.Private.CoreLib/shared/System/Decimal.cs
src/System.Private.CoreLib/shared/System/Globalization/CompareInfo.cs
src/System.Private.CoreLib/shared/System/Globalization/TextInfo.cs
src/System.Private.CoreLib/shared/System/Reflection/AssemblyName.cs
src/System.Private.CoreLib/shared/System/Reflection/StrongNameKeyPair.cs
src/System.Private.CoreLib/shared/System/ResolveEventHandler.cs
src/System.Private.CoreLib/shared/System/Runtime/Serialization/IDeserializationCallback.cs
src/System.Private.CoreLib/shared/System/Security/PermissionSet.cs
src/System.Private.CoreLib/shared/System/Text/CodePageDataItem.cs
src/System.Private.CoreLib/shared/System/Text/Encoding.cs
src/System.Private.CoreLib/shared/System/Text/StringBuilder.cs
src/System.Private.CoreLib/shared/System/TimeZoneInfo.AdjustmentRule.cs
src/System.Private.CoreLib/shared/System/TimeZoneInfo.TransitionTime.cs
src/System.Private.CoreLib/shared/System/TimeZoneInfo.cs
src/System.Private.CoreLib/src/System/Environment.CoreCLR.cs
src/System.Private.CoreLib/src/System/Runtime/CompilerServices/RuntimeHelpers.cs
src/System.Private.CoreLib/src/System/Runtime/Loader/AssemblyLoadContext.CoreCLR.cs

index d79924c..890b279 100644 (file)
@@ -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);
 
index 06e57b7..f5a90e6 100644 (file)
@@ -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
index e328726..2045702 100644 (file)
@@ -591,7 +591,7 @@ namespace System
 
         // ----- SECTION: private serialization instance methods  ----------------*
 
-        void IDeserializationCallback.OnDeserialization(object sender)
+        void IDeserializationCallback.OnDeserialization(object? sender)
         {
             try
             {
index 72ac754..47bea85 100644 (file)
@@ -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.
index dd4da0d..03e1302 100644 (file)
@@ -175,7 +175,7 @@ namespace System.Globalization
             m_name = null!;
         }
 
-        void IDeserializationCallback.OnDeserialization(object sender)
+        void IDeserializationCallback.OnDeserialization(object? sender)
         {
             OnDeserialized();
         }
index 38005a0..e5553f7 100644 (file)
@@ -63,7 +63,7 @@ namespace System.Globalization
             FinishInitialization();
         }
 
-        void IDeserializationCallback.OnDeserialization(object sender)
+        void IDeserializationCallback.OnDeserialization(object? sender)
         {
             throw new PlatformNotSupportedException();
         }
index 3de53a1..0687dcf 100644 (file)
@@ -245,7 +245,7 @@ namespace System.Reflection
             throw new PlatformNotSupportedException();
         }
 
-        public void OnDeserialization(object sender)
+        public void OnDeserialization(object? sender)
         {
             throw new PlatformNotSupportedException();
         }
index a0ba97f..52fa614 100644 (file)
@@ -50,7 +50,7 @@ namespace System.Reflection
             throw new PlatformNotSupportedException();
         }
 
-        void IDeserializationCallback.OnDeserialization(object sender)
+        void IDeserializationCallback.OnDeserialization(object? sender)
         {
             throw new PlatformNotSupportedException();
         }
index 7cb2818..a08be72 100644 (file)
@@ -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);
 }
index a1c1671..22b799c 100644 (file)
@@ -6,6 +6,6 @@ namespace System.Runtime.Serialization
 {
     public interface IDeserializationCallback
     {
-        void OnDeserialization(object sender);
+        void OnDeserialization(object? sender);
     }
 }
index 7d1327d..999d039 100644 (file)
@@ -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); }
index e2be2e3..e4b8d4d 100644 (file)
@@ -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;
index a1180a1..74f0b95 100644 (file)
@@ -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
             {
index 225442c..165ea4e 100644 (file)
@@ -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)
             {
index a3ffb1c..e2e5188 100644 (file)
@@ -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.
index 4b0abe8..aa88a14 100644 (file)
@@ -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.
index 768385c..589a605 100644 (file)
@@ -1005,7 +1005,7 @@ namespace System
                 disableDaylightSavingTime);
         }
 
-        void IDeserializationCallback.OnDeserialization(object sender)
+        void IDeserializationCallback.OnDeserialization(object? sender)
         {
             try
             {
index b2d7f11..a296a1c 100644 (file)
@@ -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
index 1c36377..9047f5e 100644 (file)
@@ -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
index 197a07e..bd56e50 100644 (file)
@@ -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 :