Fix Path.Join argument nullable annotation (dotnet/coreclr#24719)
authorStephen Toub <stoub@microsoft.com>
Wed, 22 May 2019 17:28:26 +0000 (13:28 -0400)
committerGitHub <noreply@github.com>
Wed, 22 May 2019 17:28:26 +0000 (13:28 -0400)
Commit migrated from https://github.com/dotnet/coreclr/commit/3a4ba5849ecc04a7a6749b6fb5328fa43b554deb

src/libraries/System.Private.CoreLib/src/System/IO/Path.cs

index 27741b9..674cc6e 100644 (file)
@@ -468,7 +468,7 @@ namespace System.IO
             return Join(path1.AsSpan(), path2.AsSpan(), path3.AsSpan(), path4.AsSpan());
         }
 
-        public static string Join(params string[] paths)
+        public static string Join(params string?[] paths)
         {
             if (paths == null)
             {
@@ -481,7 +481,7 @@ namespace System.IO
             }
             
             int maxSize = 0;
-            foreach (string path in paths)
+            foreach (string? path in paths)
             {
                 maxSize += path?.Length ?? 0;
             }
@@ -493,13 +493,12 @@ namespace System.IO
 
             for (int i = 0; i < paths.Length; i++)
             {
-                if ((paths[i]?.Length ?? 0) == 0)
+                string? path = paths[i];
+                if (path == null || path.Length == 0)
                 {
                     continue;
                 }
 
-                string path = paths[i];
-
                 if (builder.Length == 0)
                 {
                     builder.Append(path);