Nullable: System.Diagnostics (#23753)
authorAnirudh Agnihotry <anirudhagnihotry098@gmail.com>
Fri, 12 Apr 2019 01:07:31 +0000 (18:07 -0700)
committerStephen Toub <stoub@microsoft.com>
Fri, 12 Apr 2019 01:07:31 +0000 (21:07 -0400)
* added nullable annotation for system.Diagnostics

* fixing build errors with nullableFeature branch

* stephen feedback

* annotating files in the shared folder

* removing newline, correxting message and adding comments

24 files changed:
src/System.Private.CoreLib/shared/System/Diagnostics/ConditionalAttribute.cs
src/System.Private.CoreLib/shared/System/Diagnostics/Debug.cs
src/System.Private.CoreLib/shared/System/Diagnostics/DebugProvider.Unix.cs
src/System.Private.CoreLib/shared/System/Diagnostics/DebugProvider.Windows.cs
src/System.Private.CoreLib/shared/System/Diagnostics/DebugProvider.cs
src/System.Private.CoreLib/shared/System/Diagnostics/DebuggableAttribute.cs
src/System.Private.CoreLib/shared/System/Diagnostics/DebuggerBrowsableAttribute.cs
src/System.Private.CoreLib/shared/System/Diagnostics/DebuggerDisplayAttribute.cs
src/System.Private.CoreLib/shared/System/Diagnostics/DebuggerHiddenAttribute.cs
src/System.Private.CoreLib/shared/System/Diagnostics/DebuggerNonUserCodeAttribute.cs
src/System.Private.CoreLib/shared/System/Diagnostics/DebuggerStepThroughAttribute.cs
src/System.Private.CoreLib/shared/System/Diagnostics/DebuggerStepperBoundaryAttribute.cs
src/System.Private.CoreLib/shared/System/Diagnostics/DebuggerTypeProxyAttribute.cs
src/System.Private.CoreLib/shared/System/Diagnostics/DebuggerVisualizerAttribute.cs
src/System.Private.CoreLib/shared/System/Diagnostics/StackFrame.cs
src/System.Private.CoreLib/shared/System/Diagnostics/StackTrace.cs
src/System.Private.CoreLib/shared/System/Diagnostics/StackTraceHiddenAttribute.cs
src/System.Private.CoreLib/src/System/Diagnostics/Debugger.cs
src/System.Private.CoreLib/src/System/Diagnostics/EditAndContinueHelper.cs
src/System.Private.CoreLib/src/System/Diagnostics/ICustomDebuggerNotification.cs
src/System.Private.CoreLib/src/System/Diagnostics/StackFrame.CoreCLR.cs
src/System.Private.CoreLib/src/System/Diagnostics/StackFrameHelper.cs
src/System.Private.CoreLib/src/System/Diagnostics/StackTrace.CoreCLR.cs
src/System.Private.CoreLib/src/System/Exception.CoreCLR.cs

index 416625b..9af1e2b 100644 (file)
@@ -2,6 +2,7 @@
 // The .NET Foundation licenses this file to you under the MIT license.
 // See the LICENSE file in the project root for more information.
 
+#nullable enable
 namespace System.Diagnostics
 {
     [AttributeUsage(AttributeTargets.Method | AttributeTargets.Class, AllowMultiple = true)]
index ff56ffb..590588a 100644 (file)
@@ -2,6 +2,7 @@
 // The .NET Foundation licenses this file to you under the MIT license.
 // See the LICENSE file in the project root for more information.
 
+#nullable enable
 // Do not remove this, it is needed to retain calls to these conditional methods in release builds
 #define DEBUG
 using System.Threading;
@@ -73,13 +74,13 @@ namespace System.Diagnostics
         }
 
         [System.Diagnostics.Conditional("DEBUG")]
-        public static void Print(string message)
+        public static void Print(string? message)
         {
             Write(message);
         }
 
         [System.Diagnostics.Conditional("DEBUG")]
-        public static void Print(string format, params object[] args)
+        public static void Print(string format, params object?[] args)
         {
             Write(string.Format(null, format, args));
         }
@@ -91,13 +92,13 @@ namespace System.Diagnostics
         }
 
         [System.Diagnostics.Conditional("DEBUG")]
-        public static void Assert(bool condition, string message)
+        public static void Assert(bool condition, string? message)
         {
             Assert(condition, message, string.Empty);
         }
 
         [System.Diagnostics.Conditional("DEBUG")]
-        public static void Assert(bool condition, string message, string detailMessage)
+        public static void Assert(bool condition, string? message, string? detailMessage)
         {
             if (!condition)
             {
@@ -121,55 +122,55 @@ namespace System.Diagnostics
         }
 
         [System.Diagnostics.Conditional("DEBUG")]
-        public static void Fail(string message)
+        public static void Fail(string? message)
         {
             Fail(message, string.Empty);
         }
 
         [System.Diagnostics.Conditional("DEBUG")]
-        public static void Fail(string message, string detailMessage)
+        public static void Fail(string? message, string? detailMessage)
         {
             s_provider.Fail(message, detailMessage);
         }
 
         [System.Diagnostics.Conditional("DEBUG")]
-        public static void Assert(bool condition, string message, string detailMessageFormat, params object[] args)
+        public static void Assert(bool condition, string? message, string detailMessageFormat, params object?[] args)
         {
             Assert(condition, message, string.Format(detailMessageFormat, args));
         }
 
         [System.Diagnostics.Conditional("DEBUG")]
-        public static void WriteLine(string message)
+        public static void WriteLine(string? message)
         {
             s_provider.WriteLine(message);
         }
 
         [System.Diagnostics.Conditional("DEBUG")]
-        public static void Write(string message)
+        public static void Write(string? message)
         {
             s_provider.Write(message);
         }
 
         [System.Diagnostics.Conditional("DEBUG")]
-        public static void WriteLine(object value)
+        public static void WriteLine(object? value)
         {
             WriteLine(value?.ToString());
         }
 
         [System.Diagnostics.Conditional("DEBUG")]
-        public static void WriteLine(object value, string category)
+        public static void WriteLine(object? value, string? category)
         {
             WriteLine(value?.ToString(), category);
         }
 
         [System.Diagnostics.Conditional("DEBUG")]
-        public static void WriteLine(string format, params object[] args)
+        public static void WriteLine(string format, params object?[] args)
         {
             WriteLine(string.Format(null, format, args));
         }
 
         [System.Diagnostics.Conditional("DEBUG")]
-        public static void WriteLine(string message, string category)
+        public static void WriteLine(string? message, string? category)
         {
             if (category == null)
             {
@@ -182,13 +183,13 @@ namespace System.Diagnostics
         }
 
         [System.Diagnostics.Conditional("DEBUG")]
-        public static void Write(object value)
+        public static void Write(object? value)
         {
             Write(value?.ToString());
         }
 
         [System.Diagnostics.Conditional("DEBUG")]
-        public static void Write(string message, string category)
+        public static void Write(string? message, string? category)
         {
             if (category == null)
             {
@@ -201,13 +202,13 @@ namespace System.Diagnostics
         }
 
         [System.Diagnostics.Conditional("DEBUG")]
-        public static void Write(object value, string category)
+        public static void Write(object? value, string? category)
         {
             Write(value?.ToString(), category);
         }
 
         [System.Diagnostics.Conditional("DEBUG")]
-        public static void WriteIf(bool condition, string message)
+        public static void WriteIf(bool condition, string? message)
         {
             if (condition)
             {
@@ -216,7 +217,7 @@ namespace System.Diagnostics
         }
 
         [System.Diagnostics.Conditional("DEBUG")]
-        public static void WriteIf(bool condition, object value)
+        public static void WriteIf(bool condition, object? value)
         {
             if (condition)
             {
@@ -225,7 +226,7 @@ namespace System.Diagnostics
         }
 
         [System.Diagnostics.Conditional("DEBUG")]
-        public static void WriteIf(bool condition, string message, string category)
+        public static void WriteIf(bool condition, string? message, string? category)
         {
             if (condition)
             {
@@ -234,7 +235,7 @@ namespace System.Diagnostics
         }
 
         [System.Diagnostics.Conditional("DEBUG")]
-        public static void WriteIf(bool condition, object value, string category)
+        public static void WriteIf(bool condition, object? value, string? category)
         {
             if (condition)
             {
@@ -243,7 +244,7 @@ namespace System.Diagnostics
         }
 
         [System.Diagnostics.Conditional("DEBUG")]
-        public static void WriteLineIf(bool condition, object value)
+        public static void WriteLineIf(bool condition, object? value)
         {
             if (condition)
             {
@@ -252,7 +253,7 @@ namespace System.Diagnostics
         }
 
         [System.Diagnostics.Conditional("DEBUG")]
-        public static void WriteLineIf(bool condition, object value, string category)
+        public static void WriteLineIf(bool condition, object? value, string? category)
         {
             if (condition)
             {
@@ -261,7 +262,7 @@ namespace System.Diagnostics
         }
 
         [System.Diagnostics.Conditional("DEBUG")]
-        public static void WriteLineIf(bool condition, string message)
+        public static void WriteLineIf(bool condition, string? message)
         {
             if (condition)
             {
@@ -270,7 +271,7 @@ namespace System.Diagnostics
         }
 
         [System.Diagnostics.Conditional("DEBUG")]
-        public static void WriteLineIf(bool condition, string message, string category)
+        public static void WriteLineIf(bool condition, string? message, string? category)
         {
             if (condition)
             {
index e151717..bc3e86c 100644 (file)
@@ -2,6 +2,7 @@
 // The .NET Foundation licenses this file to you under the MIT license.
 // See the LICENSE file in the project root for more information.
 
+#nullable enable
 using Microsoft.Win32.SafeHandles;
 
 namespace System.Diagnostics
@@ -10,7 +11,7 @@ namespace System.Diagnostics
     {
         private static readonly bool s_shouldWriteToStdErr = Environment.GetEnvironmentVariable("COMPlus_DebugWriteToStdErr") == "1";
 
-        public static void FailCore(string stackTrace, string message, string detailMessage, string errorSource)
+        public static void FailCore(string stackTrace, string? message, string? detailMessage, string errorSource)
         {
             if (s_FailCore != null)
             {
@@ -77,7 +78,7 @@ namespace System.Diagnostics
             // We don't want to write UTF-16 to a file like standard error.  Ideally we would transcode this
             // to UTF8, but the downside of that is it pulls in a bunch of stuff into what is ideally
             // a path with minimal dependencies (as to prevent re-entrency), so we'll take the strategy
-            // of just throwing away any non ASCII characters from the message and writing the rest
+            // of just throwing away any non ASCII characters from the message and writing the rest            
 
             const int BufferLength = 256;
 
index 1eb445d..12ea016 100644 (file)
@@ -2,11 +2,13 @@
 // The .NET Foundation licenses this file to you under the MIT license.
 // See the LICENSE file in the project root for more information.
 
+#nullable enable
+
 namespace System.Diagnostics
 {
     public partial class DebugProvider
     {
-        public static void FailCore(string stackTrace, string message, string detailMessage, string errorSource)
+        public static void FailCore(string stackTrace, string? message, string? detailMessage, string errorSource)
         {
             if (s_FailCore != null)
             {
@@ -58,7 +60,7 @@ namespace System.Diagnostics
             // We don't want output from multiple threads to be interleaved.
             lock (s_ForLock)
             {
-                if (message == null || message.Length <= WriteChunkLength)
+                if (message.Length <= WriteChunkLength)
                 {
                     WriteToDebugger(message);
                 }
index 686fc18..3c76273 100644 (file)
@@ -2,6 +2,7 @@
 // The .NET Foundation licenses this file to you under the MIT license.
 // See the LICENSE file in the project root for more information.
 
+#nullable enable
 // Do not remove this, it is needed to retain calls to these conditional methods in release builds
 #define DEBUG
 
@@ -12,7 +13,7 @@ namespace System.Diagnostics
     /// </summary>
     public partial class DebugProvider
     {
-        public virtual void Fail(string message, string detailMessage)
+        public virtual void Fail(string? message, string? detailMessage)
         {
             string stackTrace;
             try
@@ -27,7 +28,7 @@ namespace System.Diagnostics
             FailCore(stackTrace, message, detailMessage, "Assertion Failed");
         }
 
-        internal void WriteAssert(string stackTrace, string message, string detailMessage)
+        internal void WriteAssert(string stackTrace, string? message, string? detailMessage)
         {
             WriteLine(SR.DebugAssertBanner + Environment.NewLine
                    + SR.DebugAssertShortMessage + Environment.NewLine
@@ -37,7 +38,7 @@ namespace System.Diagnostics
                    + stackTrace);
         }
 
-        public virtual void Write(string message)
+        public virtual void Write(string? message)
         {
             lock (s_lock)
             {
@@ -59,7 +60,7 @@ namespace System.Diagnostics
             }
         }
         
-        public virtual void WriteLine(string message)
+        public virtual void WriteLine(string? message)
         {
             Write(message + Environment.NewLine);
         }
@@ -72,17 +73,17 @@ namespace System.Diagnostics
 
         private sealed class DebugAssertException : Exception
         {
-            internal DebugAssertException(string stackTrace) :
+            internal DebugAssertException(string? stackTrace) :
                 base(Environment.NewLine + stackTrace)
             {
             }
 
-            internal DebugAssertException(string message, string stackTrace) :
+            internal DebugAssertException(string? message, string? stackTrace) :
                 base(message + Environment.NewLine + Environment.NewLine + stackTrace)
             {
             }
 
-            internal DebugAssertException(string message, string detailMessage, string stackTrace) :
+            internal DebugAssertException(string? message, string? detailMessage, string? stackTrace) :
                 base(message + Environment.NewLine + detailMessage + Environment.NewLine + Environment.NewLine + stackTrace)
             {
             }
@@ -90,20 +91,20 @@ namespace System.Diagnostics
 
         private bool _needIndent = true;
 
-        private string _indentString;
+        private string? _indentString;
 
         private string GetIndentString()
         {
             int indentCount = Debug.IndentSize * Debug.IndentLevel;
             if (_indentString?.Length == indentCount)
             {
-                return _indentString;
+                return _indentString!; // TODO-NULLABLE: https://github.com/dotnet/roslyn/issues/34942
             }
             return _indentString = new string(' ', indentCount);
         }
 
         // internal and not readonly so that the tests can swap this out.
-        internal static Action<string, string, string, string> s_FailCore = null;
-        internal static Action<string> s_WriteCore = null;
+        internal static Action<string, string?, string?, string>? s_FailCore = null;
+        internal static Action<string>? s_WriteCore = null;
     }
 }
index d05f847..308f683 100644 (file)
@@ -2,6 +2,8 @@
 // The .NET Foundation licenses this file to you under the MIT license.
 // See the LICENSE file in the project root for more information.
 
+#nullable enable
+
 namespace System.Diagnostics
 {
     // Attribute class used by the compiler to mark modules.  
index 8a53052..4bd42ca 100644 (file)
@@ -2,6 +2,8 @@
 // The .NET Foundation licenses this file to you under the MIT license.
 // See the LICENSE file in the project root for more information.
 
+#nullable enable
+
 namespace System.Diagnostics
 {
     //  DebuggerBrowsableState states are defined as follows:
index 7aae4b9..5f67085 100644 (file)
@@ -2,6 +2,8 @@
 // The .NET Foundation licenses this file to you under the MIT license.
 // See the LICENSE file in the project root for more information.
 
+#nullable enable
+
 namespace System.Diagnostics
 {
     // This attribute is used to control what is displayed for the given class or field 
@@ -16,9 +18,9 @@ namespace System.Diagnostics
     [AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Delegate | AttributeTargets.Enum | AttributeTargets.Field | AttributeTargets.Property | AttributeTargets.Assembly, AllowMultiple = true)]
     public sealed class DebuggerDisplayAttribute : Attribute
     {
-        private Type _target;
+        private Type? _target;
 
-        public DebuggerDisplayAttribute(string value)
+        public DebuggerDisplayAttribute(string? value)
         {
             Value = value ?? "";
             Name = "";
@@ -27,11 +29,11 @@ namespace System.Diagnostics
 
         public string Value { get; }
 
-        public string Name { get; set; }
+        public string? Name { get; set; }
 
-        public string Type { get; set; }
+        public string? Type { get; set; }
 
-        public Type Target
+        public Type? Target
         {
             get => _target;
             set
@@ -46,6 +48,6 @@ namespace System.Diagnostics
             }
         }
 
-        public string TargetTypeName { get; set; }
+        public string? TargetTypeName { get; set; }
     }
 }
index ace452e..4ee7930 100644 (file)
@@ -2,6 +2,8 @@
 // The .NET Foundation licenses this file to you under the MIT license.
 // See the LICENSE file in the project root for more information.
 
+#nullable enable
+
 namespace System.Diagnostics
 {
     [AttributeUsage(AttributeTargets.Method | AttributeTargets.Property | AttributeTargets.Constructor, Inherited = false)]
index 1b61cb7..c4e87ab 100644 (file)
@@ -2,6 +2,8 @@
 // The .NET Foundation licenses this file to you under the MIT license.
 // See the LICENSE file in the project root for more information.
 
+#nullable enable
+
 namespace System.Diagnostics
 {
     [AttributeUsage(AttributeTargets.Class | AttributeTargets.Method | AttributeTargets.Property | AttributeTargets.Constructor | AttributeTargets.Struct, Inherited = false)]
index 82a1647..633e38d 100644 (file)
@@ -2,6 +2,8 @@
 // The .NET Foundation licenses this file to you under the MIT license.
 // See the LICENSE file in the project root for more information.
 
+#nullable enable
+
 namespace System.Diagnostics
 {
 #if PROJECTN
index 647f2fd..1db7fba 100644 (file)
@@ -2,6 +2,8 @@
 // The .NET Foundation licenses this file to you under the MIT license.
 // See the LICENSE file in the project root for more information.
 
+#nullable enable
+
 namespace System.Diagnostics
 {
     /// <summary>Indicates the code following the attribute is to be executed in run, not step, mode.</summary>
index 445834e..4795228 100644 (file)
@@ -2,12 +2,14 @@
 // The .NET Foundation licenses this file to you under the MIT license.
 // See the LICENSE file in the project root for more information.
 
+#nullable enable
+
 namespace System.Diagnostics
 {
     [AttributeUsage(AttributeTargets.Struct | AttributeTargets.Class | AttributeTargets.Assembly, AllowMultiple = true)]
     public sealed class DebuggerTypeProxyAttribute : Attribute
     {
-        private Type _target;
+        private Type? _target;
 
         public DebuggerTypeProxyAttribute(Type type)
         {
@@ -19,14 +21,14 @@ namespace System.Diagnostics
             ProxyTypeName = type.AssemblyQualifiedName;
         }
 
-        public DebuggerTypeProxyAttribute(string typeName)
+        public DebuggerTypeProxyAttribute(string? typeName)
         {
             ProxyTypeName = typeName;
         }
 
-        public string ProxyTypeName { get; }
+        public string? ProxyTypeName { get; }
 
-        public Type Target
+        public Type? Target
         {
             get => _target;
             set
@@ -41,6 +43,6 @@ namespace System.Diagnostics
             }        
         }
 
-        public string TargetTypeName { get; set; }
+        public string? TargetTypeName { get; set; }
     }
 }
index 032eca8..dc1fbd2 100644 (file)
@@ -2,6 +2,8 @@
 // The .NET Foundation licenses this file to you under the MIT license.
 // See the LICENSE file in the project root for more information.
 
+#nullable enable
+
 namespace System.Diagnostics
 {
     /// <summary>
@@ -11,20 +13,20 @@ namespace System.Diagnostics
     [AttributeUsage(AttributeTargets.Struct | AttributeTargets.Class | AttributeTargets.Assembly, AllowMultiple = true)]
     public sealed class DebuggerVisualizerAttribute : Attribute
     {
-        private Type _target;
+        private Type? _target;
 
-        public DebuggerVisualizerAttribute(string visualizerTypeName)
+        public DebuggerVisualizerAttribute(string? visualizerTypeName)
         {
             VisualizerTypeName = visualizerTypeName;
         }
 
-        public DebuggerVisualizerAttribute(string visualizerTypeName, string visualizerObjectSourceTypeName)
+        public DebuggerVisualizerAttribute(string? visualizerTypeName, string? visualizerObjectSourceTypeName)
         {
             VisualizerTypeName = visualizerTypeName;
             VisualizerObjectSourceTypeName = visualizerObjectSourceTypeName;
         }
 
-        public DebuggerVisualizerAttribute(string visualizerTypeName, Type visualizerObjectSource)
+        public DebuggerVisualizerAttribute(string? visualizerTypeName, Type visualizerObjectSource)
         {
             if (visualizerObjectSource == null)
             {
@@ -60,7 +62,7 @@ namespace System.Diagnostics
             VisualizerObjectSourceTypeName = visualizerObjectSource.AssemblyQualifiedName;
         }
 
-        public DebuggerVisualizerAttribute(Type visualizer, string visualizerObjectSourceTypeName)
+        public DebuggerVisualizerAttribute(Type visualizer, string? visualizerObjectSourceTypeName)
         {
             if (visualizer == null)
             {
@@ -71,13 +73,13 @@ namespace System.Diagnostics
             VisualizerObjectSourceTypeName = visualizerObjectSourceTypeName;
         }
 
-        public string VisualizerObjectSourceTypeName { get; }
+        public string? VisualizerObjectSourceTypeName { get; }
 
-        public string VisualizerTypeName { get; }
+        public string? VisualizerTypeName { get; }
 
-        public string Description { get; set; }
+        public string? Description { get; set; }
         
-        public Type Target
+        public Type? Target
         {
             get => _target;
             set
@@ -92,6 +94,6 @@ namespace System.Diagnostics
             }
         }
 
-        public string TargetTypeName { get; set; }
+        public string? TargetTypeName { get; set; }
     }
 }
index 8c3d7af..a39c35a 100644 (file)
@@ -2,6 +2,7 @@
 // The .NET Foundation licenses this file to you under the MIT license.
 // See the LICENSE file in the project root for more information.
 
+#nullable enable
 using System.Text;
 using System.Reflection;
 
@@ -15,7 +16,7 @@ namespace System.Diagnostics
         /// <summary>
         /// Reflection information for the method if available, null otherwise.
         /// </summary>
-        private MethodBase _method;
+        private MethodBase? _method;
 
         /// <summary>
         /// Native offset of the current instruction within the current method if available,
@@ -32,7 +33,7 @@ namespace System.Diagnostics
         /// <summary>
         /// Source file name representing the current code location if available, null otherwise.
         /// </summary>
-        private string _fileName;
+        private string? _fileName;
 
         /// <summary>
         /// Line number representing the current code location if available, 0 otherwise.
@@ -96,7 +97,7 @@ namespace System.Diagnostics
         /// name and line number.  Use when you don't want to use the
         /// debugger's line mapping logic.
         /// </summary>
-        public StackFrame(string fileName, int lineNumber)
+        public StackFrame(string? fileName, int lineNumber)
         {
             InitMembers();
 
@@ -110,7 +111,7 @@ namespace System.Diagnostics
         /// name, line number and column number.  Use when you don't want to
         /// use the debugger's line mapping logic.
         /// </summary>
-        public StackFrame(string fileName, int lineNumber, int colNumber)
+        public StackFrame(string? fileName, int lineNumber, int colNumber)
             : this (fileName, lineNumber)
         {
             _columnNumber = colNumber;
@@ -126,7 +127,7 @@ namespace System.Diagnostics
         /// <summary>
         /// Returns the method the frame is executing
         /// </summary>
-        public virtual MethodBase GetMethod()
+        public virtual MethodBase? GetMethod()
         {
             return _method;
         }
@@ -156,7 +157,7 @@ namespace System.Diagnostics
         /// information is normally extracted from the debugging symbols
         /// for the executable.
         /// </summary>
-        public virtual string GetFileName()
+        public virtual string? GetFileName()
         {
             return _fileName;
         }
index 7b612a4..fccd9e1 100644 (file)
@@ -2,6 +2,7 @@
 // The .NET Foundation licenses this file to you under the MIT license.
 // See the LICENSE file in the project root for more information.
 
+#nullable enable
 using System.Collections;
 using System.Collections.Generic;
 using System.Globalization;
@@ -25,7 +26,7 @@ namespace System.Diagnostics
         /// <summary>
         /// Stack frames comprising this stack trace.
         /// </summary>
-        private StackFrame[] _stackFrames;
+        private StackFrame?[]? _stackFrames;
 
         /// <summary>
         /// Constructs a stack trace from the current location.
@@ -145,7 +146,7 @@ namespace System.Diagnostics
         /// Returns a given stack frame.  Stack frames are numbered starting at
         /// zero, which is the last stack frame pushed.
         /// </summary>
-        public virtual StackFrame GetFrame(int index)
+        public virtual StackFrame? GetFrame(int index)
         {
             if (_stackFrames != null && index < _numOfFrames && index >= 0)
                 return _stackFrames[index + _methodsToSkip];
@@ -159,7 +160,7 @@ namespace System.Diagnostics
         /// The nth element of this array is the same as GetFrame(n).
         /// The length of the array is the same as FrameCount.
         /// </summary>
-        public virtual StackFrame[] GetFrames()
+        public virtual StackFrame?[]? GetFrames()
         {
             if (_stackFrames == null || _numOfFrames <= 0)
                 return null;
@@ -204,8 +205,8 @@ namespace System.Diagnostics
             StringBuilder sb = new StringBuilder(255);
             for (int iFrameIndex = 0; iFrameIndex < _numOfFrames; iFrameIndex++)
             {
-                StackFrame sf = GetFrame(iFrameIndex);
-                MethodBase mb = sf.GetMethod();
+                StackFrame? sf = GetFrame(iFrameIndex);
+                MethodBase? mb = sf?.GetMethod();
                 if (mb != null && (ShowInStackTrace(mb) || 
                                    (iFrameIndex == _numOfFrames - 1))) // Don't filter last frame
                 {
@@ -218,7 +219,7 @@ namespace System.Diagnostics
                     sb.AppendFormat(CultureInfo.InvariantCulture, "   {0} ", word_At);
 
                     bool isAsync = false;
-                    Type declaringType = mb.DeclaringType;
+                    Type? declaringType = mb.DeclaringType;
                     string methodName = mb.Name;
                     bool methodChanged = false;
                     if (declaringType != null && declaringType.IsDefined(typeof(CompilerGeneratedAttribute), inherit: false))
@@ -226,7 +227,7 @@ namespace System.Diagnostics
                         isAsync = typeof(IAsyncStateMachine).IsAssignableFrom(declaringType);
                         if (isAsync || typeof(IEnumerator).IsAssignableFrom(declaringType))
                         {
-                            methodChanged = TryResolveStateMachineMethod(ref mb, out declaringType);
+                            methodChanged = TryResolveStateMachineMethod(ref mb!, out declaringType); // TODO-NULLABLE: https://github.com/dotnet/roslyn/issues/26761
                         }
                     }
 
@@ -265,7 +266,7 @@ namespace System.Diagnostics
                         sb.Append(']');
                     }
 
-                    ParameterInfo[] pi = null;
+                    ParameterInfo[]? pi = null;
                     try
                     {
                         pi = mb.GetParameters();
@@ -306,11 +307,11 @@ namespace System.Diagnostics
                     }
 
                     // source location printing
-                    if (sf.GetILOffset() != -1)
+                    if (sf!.GetILOffset() != -1)
                     {
                         // If we don't have a PDB or PDB-reading is disabled for the module,
                         // then the file name will be null.
-                        string fileName = sf.GetFileName();
+                        string? fileName = sf.GetFileName();
 
                         if (fileName != null)
                         {
@@ -349,13 +350,13 @@ namespace System.Diagnostics
 
             declaringType = method.DeclaringType;
 
-            Type parentType = declaringType.DeclaringType;
+            Type? parentType = declaringType.DeclaringType;
             if (parentType == null)
             {
                 return false;
             }
 
-            MethodInfo[] methods = parentType.GetMethods(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static | BindingFlags.Instance | BindingFlags.DeclaredOnly);
+            MethodInfo[]? methods = parentType.GetMethods(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static | BindingFlags.Instance | BindingFlags.DeclaredOnly);
             if (methods == null)
             {
                 return false;
@@ -363,7 +364,7 @@ namespace System.Diagnostics
 
             foreach (MethodInfo candidateMethod in methods)
             {
-                IEnumerable<StateMachineAttribute> attributes = candidateMethod.GetCustomAttributes<StateMachineAttribute>(inherit: false);
+                IEnumerable<StateMachineAttribute>? attributes = candidateMethod.GetCustomAttributes<StateMachineAttribute>(inherit: false);
                 if (attributes == null)
                 {
                     continue;
index 474274a..d12a089 100644 (file)
@@ -2,6 +2,8 @@
 // The .NET Foundation licenses this file to you under the MIT license.
 // See the LICENSE file in the project root for more information.
 
+#nullable enable
+
 namespace System.Diagnostics
 {
     [AttributeUsage(AttributeTargets.Class | AttributeTargets.Method | AttributeTargets.Constructor | AttributeTargets.Struct, Inherited = false)]
index cda3c4e..fbb8349 100644 (file)
@@ -5,6 +5,7 @@
 // The Debugger class is a part of the System.Diagnostics package
 // and is used for communicating with a debugger.
 
+#nullable enable
 using System.Runtime.CompilerServices;
 
 namespace System.Diagnostics
@@ -73,13 +74,13 @@ namespace System.Diagnostics
         // desired events are actually reported to the debugger.
         //
         // Constant representing the default category
-        public static readonly string DefaultCategory = null;
+        public static readonly string? DefaultCategory = null;
 
         // Posts a message for the attached debugger.  If there is no
         // debugger attached, has no effect.  The debugger may or may not
         // report the message depending on its settings.
         [MethodImpl(MethodImplOptions.InternalCall)]
-        public static extern void Log(int level, string category, string message);
+        public static extern void Log(int level, string? category, string? message);
 
         // Checks to see if an attached debugger has logging enabled
         //
index 89aec10..9d3b1b2 100644 (file)
@@ -11,7 +11,7 @@
 **
 =============================================================================*/
 
-
+#nullable enable
 using System;
 
 namespace System.Diagnostics
@@ -20,7 +20,7 @@ namespace System.Diagnostics
     {
 #pragma warning disable 169
 #pragma warning disable 414  // Field is not used from managed.
-        private object _objectReference;
+        private object? _objectReference;
 #pragma warning restore 414
 #pragma warning restore 169
     }
index e78734f..53bc4d2 100644 (file)
@@ -2,6 +2,7 @@
 // The .NET Foundation licenses this file to you under the MIT license.
 // See the LICENSE file in the project root for more information.
 
+#nullable enable
 using System.Text;
 
 namespace System.Diagnostics
index 56b9887..0c520e4 100644 (file)
@@ -2,6 +2,7 @@
 // The .NET Foundation licenses this file to you under the MIT license.
 // See the LICENSE file in the project root for more information.
 
+#nullable enable
 using System;
 using System.Collections;
 using System.Collections.Generic;
@@ -23,41 +24,41 @@ namespace System.Diagnostics
     // VM\DebugDebugger.h. The binder will catch some of these layout problems.
     internal class StackFrameHelper
     {
-        private Thread targetThread;
-        private int[] rgiOffset;
-        private int[] rgiILOffset;
+        private Thread? targetThread;
+        private int[]? rgiOffset;
+        private int[]? rgiILOffset;
 
 #pragma warning disable 414
         // dynamicMethods is an array of System.Resolver objects, used to keep
         // DynamicMethodDescs AND collectible LoaderAllocators alive for the lifetime of StackFrameHelper.
-        private object dynamicMethods; // Field is not used from managed.        
-
-        private IntPtr[] rgMethodHandle;
-        private string[] rgAssemblyPath;
-        private Assembly[] rgAssembly;
-        private IntPtr[] rgLoadedPeAddress;
-        private int[] rgiLoadedPeSize;
-        private IntPtr[] rgInMemoryPdbAddress;
-        private int[] rgiInMemoryPdbSize;
+        private object? dynamicMethods; // Field is not used from managed.        
+
+        private IntPtr[]? rgMethodHandle;
+        private string[]? rgAssemblyPath;
+        private Assembly?[]? rgAssembly;
+        private IntPtr[]? rgLoadedPeAddress;
+        private int[]? rgiLoadedPeSize;
+        private IntPtr[]? rgInMemoryPdbAddress;
+        private int[]? rgiInMemoryPdbSize;
         // if rgiMethodToken[i] == 0, then don't attempt to get the portable PDB source/info
-        private int[] rgiMethodToken;
-        private string[] rgFilename;
-        private int[] rgiLineNumber;
-        private int[] rgiColumnNumber;
-        private bool[] rgiLastFrameFromForeignExceptionStackTrace;
+        private int[]? rgiMethodToken;
+        private string?[]? rgFilename;
+        private int[]? rgiLineNumber;
+        private int[]? rgiColumnNumber;
+        private bool[]? rgiLastFrameFromForeignExceptionStackTrace;
         private int iFrameCount;
 #pragma warning restore 414
 
-        private delegate void GetSourceLineInfoDelegate(Assembly assembly, string assemblyPath, IntPtr loadedPeAddress,
+        private delegate void GetSourceLineInfoDelegate(Assembly? assembly, string assemblyPath, IntPtr loadedPeAddress,
             int loadedPeSize, IntPtr inMemoryPdbAddress, int inMemoryPdbSize, int methodToken, int ilOffset,
-            out string sourceFile, out int sourceLine, out int sourceColumn);
+            out string? sourceFile, out int sourceLine, out int sourceColumn);
 
-        private static GetSourceLineInfoDelegate s_getSourceLineInfo = null;
+        private static GetSourceLineInfoDelegate? s_getSourceLineInfo = null;
 
         [ThreadStatic]
         private static int t_reentrancy = 0;
 
-        public StackFrameHelper(Thread target)
+        public StackFrameHelper(Thread? target)
         {
             targetThread = target;
             rgMethodHandle = null;
@@ -92,7 +93,7 @@ namespace System.Diagnostics
         // rgiLineNumber and rgiColumnNumber fields using the portable PDB reader if not already
         // done by GetStackFramesInternal (on Windows for old PDB format).
         //
-        internal void InitializeSourceInfo(int iSkip, bool fNeedFileInfo, Exception exception)
+        internal void InitializeSourceInfo(int iSkip, bool fNeedFileInfo, Exception? exception)
         {
             StackTrace.GetStackFramesInternal(this, iSkip, fNeedFileInfo, exception);
 
@@ -108,7 +109,7 @@ namespace System.Diagnostics
             {
                 if (s_getSourceLineInfo == null)
                 {
-                    Type symbolsType = Type.GetType(
+                    Type? symbolsType = Type.GetType(
                         "System.Diagnostics.StackTraceSymbols, System.Diagnostics.StackTrace, Version=4.0.1.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a",
                         throwOnError: false);
 
@@ -123,14 +124,14 @@ namespace System.Diagnostics
                         typeof(int), typeof(int), typeof(int), 
                         typeof(string).MakeByRefType(), typeof(int).MakeByRefType(), typeof(int).MakeByRefType() 
                     };
-                    MethodInfo symbolsMethodInfo = symbolsType.GetMethod("GetSourceLineInfo", BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Instance, null, parameterTypes, null);
+                    MethodInfo? symbolsMethodInfo = symbolsType.GetMethod("GetSourceLineInfo", BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Instance, null, parameterTypes, null);
                     if (symbolsMethodInfo == null)
                     {
                         return;
                     }
 
                     // Create an instance of System.Diagnostics.Stacktrace.Symbols
-                    object target = Activator.CreateInstance(symbolsType);
+                    object? target = Activator.CreateInstance(symbolsType);
 
                     // Create an instance delegate for the GetSourceLineInfo method
                     GetSourceLineInfoDelegate getSourceLineInfo = (GetSourceLineInfoDelegate)symbolsMethodInfo.CreateDelegate(typeof(GetSourceLineInfoDelegate), target);
@@ -144,11 +145,11 @@ namespace System.Diagnostics
                 {
                     // If there was some reason not to try get the symbols from the portable PDB reader like the module was
                     // ENC or the source/line info was already retrieved, the method token is 0.
-                    if (rgiMethodToken[index] != 0)
+                    if (rgiMethodToken![index] != 0)
                     {
-                        s_getSourceLineInfo(rgAssembly[index], rgAssemblyPath[index], rgLoadedPeAddress[index], rgiLoadedPeSize[index],
-                            rgInMemoryPdbAddress[index], rgiInMemoryPdbSize[index], rgiMethodToken[index],
-                            rgiILOffset[index], out rgFilename[index], out rgiLineNumber[index], out rgiColumnNumber[index]);
+                        s_getSourceLineInfo!(rgAssembly![index], rgAssemblyPath![index]!, rgLoadedPeAddress![index], rgiLoadedPeSize![index],
+                            rgInMemoryPdbAddress![index], rgiInMemoryPdbSize![index], rgiMethodToken![index],
+                            rgiILOffset![index], out rgFilename![index], out rgiLineNumber![index], out rgiColumnNumber![index]);
                     }
                 }
             }
@@ -161,26 +162,26 @@ namespace System.Diagnostics
             }
         }
 
-        public virtual MethodBase GetMethodBase(int i)
+        public virtual MethodBase? GetMethodBase(int i)
         {
             // There may be a better way to do this.
             // we got RuntimeMethodHandles here and we need to go to MethodBase
             // but we don't know whether the reflection info has been initialized
             // or not. So we call GetMethods and GetConstructors on the type
             // and then we fetch the proper MethodBase!!
-            IntPtr mh = rgMethodHandle[i];
+            IntPtr mh = rgMethodHandle![i];
 
             if (mh == IntPtr.Zero)
                 return null;
 
-            IRuntimeMethodInfo mhReal = RuntimeMethodHandle.GetTypicalMethodDefinition(new RuntimeMethodInfoStub(mh, this));
+            IRuntimeMethodInfo? mhReal = RuntimeMethodHandle.GetTypicalMethodDefinition(new RuntimeMethodInfoStub(mh, this));
 
             return RuntimeType.GetMethodBase(mhReal);
         }
 
-        public virtual int GetOffset(int i) { return rgiOffset[i]; }
-        public virtual int GetILOffset(int i) { return rgiILOffset[i]; }
-        public virtual string GetFilename(int i) { return rgFilename == null ? null : rgFilename[i]; }
+        public virtual int GetOffset(int i) { return rgiOffset![i]; }
+        public virtual int GetILOffset(int i) { return rgiILOffset![i]; }
+        public virtual string? GetFilename(int i) { return rgFilename == null ? null : rgFilename[i]; }
         public virtual int GetLineNumber(int i) { return rgiLineNumber == null ? 0 : rgiLineNumber[i]; }
         public virtual int GetColumnNumber(int i) { return rgiColumnNumber == null ? 0 : rgiColumnNumber[i]; }
 
index 5c8a8c5..a86f8ba 100644 (file)
@@ -2,6 +2,7 @@
 // The .NET Foundation licenses this file to you under the MIT license.
 // See the LICENSE file in the project root for more information.
 
+#nullable enable
 using System.Threading;
 using System.Runtime.CompilerServices;
 using System.Reflection;
@@ -11,7 +12,7 @@ namespace System.Diagnostics
     public partial class StackTrace
     {
         [MethodImplAttribute(MethodImplOptions.InternalCall)]
-        internal static extern void GetStackFramesInternal(StackFrameHelper sfh, int iSkip, bool fNeedFileInfo, Exception e);
+        internal static extern void GetStackFramesInternal(StackFrameHelper sfh, int iSkip, bool fNeedFileInfo, Exception? e);
 
         internal static int CalculateFramesToSkip(StackFrameHelper StackF, int iNumFrames)
         {
@@ -23,13 +24,13 @@ namespace System.Diagnostics
             // System.Diagnostics functions
             for (int i = 0; i < iNumFrames; i++)
             {
-                MethodBase mb = StackF.GetMethodBase(i);
+                MethodBase? mb = StackF.GetMethodBase(i);
                 if (mb != null)
                 {
-                    Type t = mb.DeclaringType;
+                    Type? t = mb.DeclaringType;
                     if (t == null)
                         break;
-                    string ns = t.Namespace;
+                    string? ns = t.Namespace;
                     if (ns == null)
                         break;
                     if (!string.Equals(ns, PackageName, StringComparison.Ordinal))
@@ -41,7 +42,7 @@ namespace System.Diagnostics
             return iRetVal;
         }
 
-        private void InitializeForException(Exception exception, int skipFrames, bool fNeedFileInfo)
+        private void InitializeForException(Exception? exception, int skipFrames, bool fNeedFileInfo)
         {
             CaptureStackTrace(skipFrames, fNeedFileInfo, exception);
         }
@@ -55,7 +56,7 @@ namespace System.Diagnostics
         /// Retrieves an object with stack trace information encoded.
         /// It leaves out the first "iSkip" lines of the stacktrace.
         /// </summary>
-        private void CaptureStackTrace(int skipFrames, bool fNeedFileInfo, Exception e)
+        private void CaptureStackTrace(int skipFrames, bool fNeedFileInfo, Exception? e)
         {
             _methodsToSkip = skipFrames;
 
index 119f09d..897e530 100644 (file)
@@ -206,8 +206,8 @@ namespace System
             StackTrace st = new StackTrace(this, fNeedFileInfo: false);
             if (st.FrameCount > 0)
             {
-                StackFrame sf = st.GetFrame(0);
-                MethodBase method = sf.GetMethod();
+                StackFrame sf = st.GetFrame(0)!;
+                MethodBase method = sf.GetMethod()!;
 
                 Module module = method.Module;