The compiler is now analyzing statics. Get compliant.
// 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
}
#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)
{
{
#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;
{
// 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;
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
/// </summary>
internal static DateTimeFormatInfo GetJapaneseCalendarDTFI()
{
- DateTimeFormatInfo temp = s_jajpDTFI;
+ DateTimeFormatInfo? temp = s_jajpDTFI;
if (temp == null)
{
temp = new CultureInfo("ja-JP", false).DateTimeFormat;
/// </summary>
internal static DateTimeFormatInfo GetTaiwanCalendarDTFI()
{
- DateTimeFormatInfo temp = s_zhtwDTFI;
+ DateTimeFormatInfo? temp = s_zhtwDTFI;
if (temp == null)
{
temp = new CultureInfo("zh-TW", false).DateTimeFormat;
// 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
{
s_knownWords = temp;
}
- return (s_knownWords);
+ return s_knownWords;
}
}
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;
});
}
- internal static volatile Calendar s_defaultInstance;
+ internal static volatile Calendar? s_defaultInstance;
internal GregorianCalendarHelper _helper;
internal static Calendar GetDefaultInstance()
/// </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 };
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;
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;
callback(rwc);
}
- private static ContextCallback s_invokeAsyncCallback;
+ private static ContextCallback? s_invokeAsyncCallback;
void ITaskCompletionAction.Invoke(Task completingTask)
{
}
[ThreadStatic]
- private static Random t_threadRandom;
+ private static Random? t_threadRandom;
private static readonly Random s_globalRandom = new Random(GenerateGlobalSeed());
/*=====================================GenerateSeed=====================================
========================================================================================*/
private static int GenerateSeed()
{
- Random rnd = t_threadRandom;
+ Random? rnd = t_threadRandom;
if (rnd == null)
{
int seed;
// 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()
{
internal bool LocalFindAndPop(object callback)
{
- ThreadPoolWorkQueueThreadLocals tl = ThreadPoolWorkQueueThreadLocals.threadLocals;
+ ThreadPoolWorkQueueThreadLocals? tl = ThreadPoolWorkQueueThreadLocals.threadLocals;
return tl != null && tl.workStealingQueue.LocalFindAndPop(callback);
}
internal sealed class ThreadPoolWorkQueueThreadLocals
{
[ThreadStatic]
- public static ThreadPoolWorkQueueThreadLocals threadLocals;
+ public static ThreadPoolWorkQueueThreadLocals? threadLocals;
public readonly ThreadPoolWorkQueue workQueue;
public readonly ThreadPoolWorkQueue.WorkStealingQueue workStealingQueue;
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;
[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;
// 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();
//
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)
{
{
internal static class WindowsRuntimeMetadata
{
- private static EventHandler<DesignerNamespaceResolveEventArgs> DesignerNamespaceResolve;
+ private static EventHandler<DesignerNamespaceResolveEventArgs>? DesignerNamespaceResolve;
internal static string[]? OnDesignerNamespaceResolve(string namespaceName)
{
}
}
- private static OleAutBinder s_ForwardCallBinder;
+ private static OleAutBinder? s_ForwardCallBinder;
private OleAutBinder ForwardCallBinder
{
get => s_ForwardCallBinder ?? (s_ForwardCallBinder = new OleAutBinder());
// 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.
//
//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]