Fix nullability annotations for static (#25914)
authorStephen Toub <stoub@microsoft.com>
Mon, 29 Jul 2019 00:14:40 +0000 (20:14 -0400)
committerGitHub <noreply@github.com>
Mon, 29 Jul 2019 00:14:40 +0000 (20:14 -0400)
The compiler is now analyzing statics.  Get compliant.

21 files changed:
src/System.Private.CoreLib/shared/System/Diagnostics/Tracing/EventSource.cs
src/System.Private.CoreLib/shared/System/Environment.Win32.cs
src/System.Private.CoreLib/shared/System/Globalization/CultureInfo.Windows.cs
src/System.Private.CoreLib/shared/System/Globalization/DateTimeFormatInfo.cs
src/System.Private.CoreLib/shared/System/Globalization/DateTimeFormatInfoScanner.cs
src/System.Private.CoreLib/shared/System/Globalization/GregorianCalendar.cs
src/System.Private.CoreLib/shared/System/Globalization/JapaneseCalendar.cs
src/System.Private.CoreLib/shared/System/Globalization/NumberFormatInfo.cs
src/System.Private.CoreLib/shared/System/Globalization/TaiwanCalendar.cs
src/System.Private.CoreLib/shared/System/IO/FileStreamCompletionSource.Win32.cs
src/System.Private.CoreLib/shared/System/IO/Stream.cs
src/System.Private.CoreLib/shared/System/Random.cs
src/System.Private.CoreLib/shared/System/Runtime/Serialization/SerializationInfo.cs
src/System.Private.CoreLib/shared/System/Threading/ThreadPool.cs
src/System.Private.CoreLib/src/System/Diagnostics/Eventing/RuntimeEventSource.cs
src/System.Private.CoreLib/src/System/Reflection/Emit/DynamicMethod.cs
src/System.Private.CoreLib/src/System/Runtime/InteropServices/WindowsRuntime/CLRIPropertyValueImpl.cs
src/System.Private.CoreLib/src/System/Runtime/InteropServices/WindowsRuntime/WindowsRuntimeMetadata.cs
src/System.Private.CoreLib/src/System/RuntimeType.CoreCLR.cs
src/System.Private.CoreLib/src/System/String.CoreCLR.cs
src/System.Private.CoreLib/src/System/Threading/Tasks/AsyncCausalityTracer.cs

index 93687a6..b03011c 100644 (file)
@@ -3956,7 +3956,7 @@ namespace System.Diagnostics.Tracing
         // Rather than depending on initialized statics, use lazy initialization to ensure that the statics are initialized exactly when they are needed.
 
         // used for generating GUID from eventsource name
-        private static byte[] namespaceBytes;
+        private static byte[]? namespaceBytes;
 
 #endregion
     }
index 78d49b1..37213f0 100644 (file)
@@ -404,7 +404,7 @@ namespace System
 #if FEATURE_APPX
         private static class WinRTFolderPaths
         {
-            private static Func<SpecialFolder, SpecialFolderOption, string> s_winRTFolderPathsGetFolderPath;
+            private static Func<SpecialFolder, SpecialFolderOption, string>? s_winRTFolderPathsGetFolderPath;
 
             public static string GetFolderPath(SpecialFolder folder, SpecialFolderOption option)
             {
index d746659..775ee4e 100644 (file)
@@ -13,7 +13,7 @@ namespace System.Globalization
     {
 #if FEATURE_APPX
         // When running under AppX, we use this to get some information about the language list
-        private static volatile WindowsRuntimeResourceManagerBase s_WindowsRuntimeResourceManager;
+        private static volatile WindowsRuntimeResourceManagerBase? s_WindowsRuntimeResourceManager;
 
         [ThreadStatic]
         private static bool ts_IsDoingAppXCultureInfoLookup;
index b8167d9..db64442 100644 (file)
@@ -51,7 +51,7 @@ namespace System.Globalization
     {
         // cache for the invariant culture.
         // invariantInfo is constant irrespective of your current culture.
-        private static volatile DateTimeFormatInfo s_invariantInfo;
+        private static volatile DateTimeFormatInfo? s_invariantInfo;
 
         // an index which points to a record in Culture Data Table.
         private CultureData _cultureData;
@@ -2135,8 +2135,8 @@ namespace System.Globalization
         internal const string JapaneseLangName = "ja";
         internal const string EnglishLangName = "en";
 
-        private static volatile DateTimeFormatInfo s_jajpDTFI;
-        private static volatile DateTimeFormatInfo s_zhtwDTFI;
+        private static volatile DateTimeFormatInfo? s_jajpDTFI;
+        private static volatile DateTimeFormatInfo? s_zhtwDTFI;
 
         /// <summary>
         /// Create a Japanese DTFI which uses JapaneseCalendar.  This is used to parse
@@ -2146,7 +2146,7 @@ namespace System.Globalization
         /// </summary>
         internal static DateTimeFormatInfo GetJapaneseCalendarDTFI()
         {
-            DateTimeFormatInfo temp = s_jajpDTFI;
+            DateTimeFormatInfo? temp = s_jajpDTFI;
             if (temp == null)
             {
                 temp = new CultureInfo("ja-JP", false).DateTimeFormat;
@@ -2164,7 +2164,7 @@ namespace System.Globalization
         /// </summary>
         internal static DateTimeFormatInfo GetTaiwanCalendarDTFI()
         {
-            DateTimeFormatInfo temp = s_zhtwDTFI;
+            DateTimeFormatInfo? temp = s_zhtwDTFI;
             if (temp == null)
             {
                 temp = new CultureInfo("zh-TW", false).DateTimeFormat;
index 7b5ae00..accc5b9 100644 (file)
@@ -115,7 +115,7 @@ namespace System.Globalization
         // The collection fo date words & postfix.
         internal List<string> m_dateWords = new List<string>();
         // Hashtable for the known words.
-        private static volatile Dictionary<string, string> s_knownWords;
+        private static volatile Dictionary<string, string>? s_knownWords;
 
         static Dictionary<string, string> KnownWords
         {
@@ -147,7 +147,7 @@ namespace System.Globalization
 
                     s_knownWords = temp;
                 }
-                return (s_knownWords);
+                return s_knownWords;
             }
         }
 
index ebc5a54..2be5a22 100644 (file)
@@ -27,7 +27,7 @@ namespace System.Globalization
 
         private static readonly int[] DaysToMonth366 = { 0, 31, 60, 91, 121, 152, 182, 213, 244, 274, 305, 335, 366 };
 
-        private static volatile Calendar s_defaultInstance;
+        private static volatile Calendar? s_defaultInstance;
 
         public override DateTime MinSupportedDateTime => DateTime.MinValue;
 
index b0428db..fcc2302 100644 (file)
@@ -81,7 +81,7 @@ namespace System.Globalization
                 });
         }
 
-        internal static volatile Calendar s_defaultInstance;
+        internal static volatile Calendar? s_defaultInstance;
         internal GregorianCalendarHelper _helper;
 
         internal static Calendar GetDefaultInstance()
index 3078c8e..7af0381 100644 (file)
@@ -35,7 +35,7 @@ namespace System.Globalization
     /// </remarks>
     public sealed class NumberFormatInfo : IFormatProvider, ICloneable
     {
-        private static volatile NumberFormatInfo s_invariantInfo;
+        private static volatile NumberFormatInfo? s_invariantInfo;
 
         internal int[] _numberGroupSizes = new int[] { 3 };
         internal int[] _currencyGroupSizes = new int[] { 3 };
index e190f66..a0f64c9 100644 (file)
@@ -30,7 +30,7 @@ namespace System.Globalization
             new EraInfo( 1, 1912, 1, 1, 1911, 1, GregorianCalendar.MaxYear - 1911)    // era #, start year/month/day, yearOffset, minEraYear
         };
 
-        private static volatile Calendar s_defaultInstance;
+        private static volatile Calendar? s_defaultInstance;
 
         private readonly GregorianCalendarHelper _helper;
 
index 837946e..246538b 100644 (file)
@@ -24,7 +24,7 @@ namespace System.IO
             private const long CompletedCallback = (long)8 << 32;
             private const ulong ResultMask = ((ulong)uint.MaxValue) << 32;
 
-            private static Action<object?> s_cancelCallback;
+            private static Action<object?>? s_cancelCallback;
 
             private readonly FileStream _stream;
             private readonly int _numBufferedBytes;
index 4b3b0d3..85899ef 100644 (file)
@@ -644,7 +644,7 @@ namespace System.IO
                 callback(rwc);
             }
 
-            private static ContextCallback s_invokeAsyncCallback;
+            private static ContextCallback? s_invokeAsyncCallback;
 
             void ITaskCompletionAction.Invoke(Task completingTask)
             {
index ed79732..709fc0c 100644 (file)
@@ -116,7 +116,7 @@ namespace System
         }
 
         [ThreadStatic]
-        private static Random t_threadRandom;
+        private static Random? t_threadRandom;
         private static readonly Random s_globalRandom = new Random(GenerateGlobalSeed());
 
         /*=====================================GenerateSeed=====================================
@@ -125,7 +125,7 @@ namespace System
         ========================================================================================*/
         private static int GenerateSeed()
         {
-            Random rnd = t_threadRandom;
+            Random? rnd = t_threadRandom;
             if (rnd == null)
             {
                 int seed;
index a11fa94..57f1cf0 100644 (file)
@@ -32,7 +32,7 @@ namespace System.Runtime.Serialization
         // On AoT, assume private members are reflection blocked, so there's no further protection required
         // for the thread's DeserializationTracker
         [ThreadStatic]
-        private static DeserializationTracker t_deserializationTracker;
+        private static DeserializationTracker? t_deserializationTracker;
 
         private static DeserializationTracker GetThreadDeserializationTracker()
         {
index dca22ab..21d8e8f 100644 (file)
@@ -494,7 +494,7 @@ namespace System.Threading
 
         internal bool LocalFindAndPop(object callback)
         {
-            ThreadPoolWorkQueueThreadLocals tl = ThreadPoolWorkQueueThreadLocals.threadLocals;
+            ThreadPoolWorkQueueThreadLocals? tl = ThreadPoolWorkQueueThreadLocals.threadLocals;
             return tl != null && tl.workStealingQueue.LocalFindAndPop(callback);
         }
 
@@ -728,7 +728,7 @@ namespace System.Threading
     internal sealed class ThreadPoolWorkQueueThreadLocals
     {
         [ThreadStatic]
-        public static ThreadPoolWorkQueueThreadLocals threadLocals;
+        public static ThreadPoolWorkQueueThreadLocals? threadLocals;
 
         public readonly ThreadPoolWorkQueue workQueue;
         public readonly ThreadPoolWorkQueue.WorkStealingQueue workStealingQueue;
@@ -1231,7 +1231,7 @@ namespace System.Threading
 
         internal static IEnumerable<object> GetLocallyQueuedWorkItems()
         {
-            ThreadPoolWorkQueue.WorkStealingQueue wsq = ThreadPoolWorkQueueThreadLocals.threadLocals.workStealingQueue;
+            ThreadPoolWorkQueue.WorkStealingQueue? wsq = ThreadPoolWorkQueueThreadLocals.threadLocals?.workStealingQueue;
             if (wsq != null && wsq.m_array != null)
             {
                 object?[] items = wsq.m_array;
index f8498a6..5e6f57d 100644 (file)
@@ -12,7 +12,7 @@ namespace System.Diagnostics.Tracing
     [EventSource(Guid="49592C0F-5A05-516D-AA4B-A64E02026C89", Name = "System.Runtime")]
     internal sealed class RuntimeEventSource : EventSource
     {
-        private static RuntimeEventSource s_RuntimeEventSource;
+        private static RuntimeEventSource? s_RuntimeEventSource;
         private PollingCounter? _gcHeapSizeCounter;
         private IncrementingPollingCounter? _gen0GCCounter;
         private IncrementingPollingCounter? _gen1GCCounter;
index 0991b09..11db43e 100644 (file)
@@ -41,7 +41,7 @@ namespace System.Reflection.Emit
         // We capture the creation context so that we can do the checks against the same context,
         // irrespective of when the method gets compiled. Note that the DynamicMethod does not know when
         // it is ready for use since there is not API which indictates that IL generation has completed.
-        private static volatile InternalModuleBuilder s_anonymouslyHostedDynamicMethodsModule;
+        private static volatile InternalModuleBuilder? s_anonymouslyHostedDynamicMethodsModule;
         private static readonly object s_anonymouslyHostedDynamicMethodsModuleLock = new object();
 
         //
index 752f7bc..b4b1b59 100644 (file)
@@ -15,7 +15,7 @@ namespace System.Runtime.InteropServices.WindowsRuntime
         private object _data;
 
         // Numeric scalar types which participate in coersion
-        private static volatile Tuple<Type, PropertyType>[] s_numericScalarTypes;
+        private static volatile Tuple<Type, PropertyType>[]? s_numericScalarTypes;
 
         internal CLRIPropertyValueImpl(PropertyType type, object data)
         {
index ce1d0ef..273b270 100644 (file)
@@ -8,7 +8,7 @@ namespace System.Runtime.InteropServices.WindowsRuntime
 {
     internal static class WindowsRuntimeMetadata
     {
-        private static EventHandler<DesignerNamespaceResolveEventArgs> DesignerNamespaceResolve;
+        private static EventHandler<DesignerNamespaceResolveEventArgs>? DesignerNamespaceResolve;
 
         internal static string[]? OnDesignerNamespaceResolve(string namespaceName)
         {
index 6e7527c..02518db 100644 (file)
@@ -4342,7 +4342,7 @@ namespace System
             }
         }
 
-        private static OleAutBinder s_ForwardCallBinder;
+        private static OleAutBinder? s_ForwardCallBinder;
         private OleAutBinder ForwardCallBinder
         {
             get => s_ForwardCallBinder ?? (s_ForwardCallBinder = new OleAutBinder());
index b942ea5..79eeca6 100644 (file)
@@ -31,8 +31,10 @@ namespace System
         // We need to call the String constructor so that the compiler doesn't mark this as a literal.
         // Marking this as a literal would mean that it doesn't show up as a field which we can access 
         // from native.
+#pragma warning disable CS8618 // compiler sees this non-nullable static string as uninitialized
         [Intrinsic]
         public static readonly string Empty;
+#pragma warning restore CS8618
 
         // Gets the character at a specified position.
         //
index 3332f44..614b61e 100644 (file)
@@ -33,8 +33,7 @@ namespace System.Threading.Tasks
         //Indicates this information comes from the BCL Library
         private const WFD.CausalitySource s_CausalitySource = WFD.CausalitySource.Library;
 
-        //Lazy initialize the actual factory
-        private static WFD.IAsyncCausalityTracerStatics s_TracerFactory;
+        private static WFD.IAsyncCausalityTracerStatics s_TracerFactory = null!;
 
         // The loggers that this Tracer knows about. 
         [Flags]