From 7c47db100d78549379fd4b04bd490bba06831005 Mon Sep 17 00:00:00 2001 From: Ilya Date: Thu, 5 Nov 2020 21:44:00 +0500 Subject: [PATCH 1/3] File.Exists() is not null when true --- src/libraries/System.IO.FileSystem/ref/System.IO.FileSystem.cs | 2 +- src/libraries/System.IO.FileSystem/src/System/IO/File.cs | 2 +- src/libraries/System.Private.CoreLib/src/Internal/IO/File.cs | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/libraries/System.IO.FileSystem/ref/System.IO.FileSystem.cs b/src/libraries/System.IO.FileSystem/ref/System.IO.FileSystem.cs index f84978d9b5e1f6..8b3152eda51c98 100644 --- a/src/libraries/System.IO.FileSystem/ref/System.IO.FileSystem.cs +++ b/src/libraries/System.IO.FileSystem/ref/System.IO.FileSystem.cs @@ -23,7 +23,7 @@ public static void Delete(string path, bool recursive) { } public static System.Collections.Generic.IEnumerable EnumerateFileSystemEntries(string path, string searchPattern) { throw null; } public static System.Collections.Generic.IEnumerable EnumerateFileSystemEntries(string path, string searchPattern, System.IO.EnumerationOptions enumerationOptions) { throw null; } public static System.Collections.Generic.IEnumerable EnumerateFileSystemEntries(string path, string searchPattern, System.IO.SearchOption searchOption) { throw null; } - public static bool Exists(string? path) { throw null; } + public static bool Exists([NotNullWhen(true)] string? path) { throw null; } public static System.DateTime GetCreationTime(string path) { throw null; } public static System.DateTime GetCreationTimeUtc(string path) { throw null; } public static string GetCurrentDirectory() { throw null; } diff --git a/src/libraries/System.IO.FileSystem/src/System/IO/File.cs b/src/libraries/System.IO.FileSystem/src/System/IO/File.cs index 1b089a91ffc883..4c86dd94c5ad1c 100644 --- a/src/libraries/System.IO.FileSystem/src/System/IO/File.cs +++ b/src/libraries/System.IO.FileSystem/src/System/IO/File.cs @@ -114,7 +114,7 @@ public static void Delete(string path) // given by the specified path exists; otherwise, the result is // false. Note that if path describes a directory, // Exists will return true. - public static bool Exists(string? path) + public static bool Exists([NotNullWhen(true)] string? path) { try { diff --git a/src/libraries/System.Private.CoreLib/src/Internal/IO/File.cs b/src/libraries/System.Private.CoreLib/src/Internal/IO/File.cs index 56f85c752b5242..c6fd26dc9b4c61 100644 --- a/src/libraries/System.Private.CoreLib/src/Internal/IO/File.cs +++ b/src/libraries/System.Private.CoreLib/src/Internal/IO/File.cs @@ -18,7 +18,7 @@ internal static partial class File // given by the specified path exists; otherwise, the result is // false. Note that if path describes a directory, // Exists will return true. - public static bool Exists(string? path) + public static bool Exists([NotNullWhen(true)] string? path) { try { From 9ad58753f2d8d6c8bd85f0a45d69e246342001d9 Mon Sep 17 00:00:00 2001 From: Ilya Date: Thu, 5 Nov 2020 22:04:23 +0500 Subject: [PATCH 2/3] Fix compile --- src/libraries/System.IO.FileSystem/ref/System.IO.FileSystem.cs | 2 +- src/libraries/System.Private.CoreLib/src/Internal/IO/File.cs | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/src/libraries/System.IO.FileSystem/ref/System.IO.FileSystem.cs b/src/libraries/System.IO.FileSystem/ref/System.IO.FileSystem.cs index 8b3152eda51c98..c1790b0658ce64 100644 --- a/src/libraries/System.IO.FileSystem/ref/System.IO.FileSystem.cs +++ b/src/libraries/System.IO.FileSystem/ref/System.IO.FileSystem.cs @@ -23,7 +23,7 @@ public static void Delete(string path, bool recursive) { } public static System.Collections.Generic.IEnumerable EnumerateFileSystemEntries(string path, string searchPattern) { throw null; } public static System.Collections.Generic.IEnumerable EnumerateFileSystemEntries(string path, string searchPattern, System.IO.EnumerationOptions enumerationOptions) { throw null; } public static System.Collections.Generic.IEnumerable EnumerateFileSystemEntries(string path, string searchPattern, System.IO.SearchOption searchOption) { throw null; } - public static bool Exists([NotNullWhen(true)] string? path) { throw null; } + public static bool Exists([System.Diagnostics.CodeAnalysis.NotNullWhen(true)] string? path) { throw null; } public static System.DateTime GetCreationTime(string path) { throw null; } public static System.DateTime GetCreationTimeUtc(string path) { throw null; } public static string GetCurrentDirectory() { throw null; } diff --git a/src/libraries/System.Private.CoreLib/src/Internal/IO/File.cs b/src/libraries/System.Private.CoreLib/src/Internal/IO/File.cs index c6fd26dc9b4c61..b3aa37ad891e34 100644 --- a/src/libraries/System.Private.CoreLib/src/Internal/IO/File.cs +++ b/src/libraries/System.Private.CoreLib/src/Internal/IO/File.cs @@ -3,6 +3,7 @@ using System; using System.Diagnostics; +using System.Diagnostics.CodeAnalysis; using System.Security; using System.IO; From 923768b25810e24fb8ab2476a01e1ea9b35279f5 Mon Sep 17 00:00:00 2001 From: Ilya Date: Thu, 5 Nov 2020 22:25:29 +0500 Subject: [PATCH 3/3] Fix compile 2 --- src/libraries/System.IO.FileSystem/src/System/IO/File.cs | 1 + 1 file changed, 1 insertion(+) diff --git a/src/libraries/System.IO.FileSystem/src/System/IO/File.cs b/src/libraries/System.IO.FileSystem/src/System/IO/File.cs index 4c86dd94c5ad1c..9f597548564731 100644 --- a/src/libraries/System.IO.FileSystem/src/System/IO/File.cs +++ b/src/libraries/System.IO.FileSystem/src/System/IO/File.cs @@ -5,6 +5,7 @@ using System.Buffers; using System.Collections.Generic; using System.Diagnostics; +using System.Diagnostics.CodeAnalysis; using System.IO; using System.Runtime.ExceptionServices; using System.Runtime.Versioning;