Fix Version's comparer operators to allow null (#23898)
authorStephen Toub <stoub@microsoft.com>
Fri, 12 Apr 2019 00:47:35 +0000 (20:47 -0400)
committerGitHub <noreply@github.com>
Fri, 12 Apr 2019 00:47:35 +0000 (20:47 -0400)
Previously for `<`/`<=` it would throw if `v1` argument was null, but for `>`/`>=` would throw if the `v1` argument was null, albeit using `v1` in the exception parameter name.  It's also not expected for comparisons like this to throw, in general.

src/System.Private.CoreLib/shared/System/Version.cs
tests/CoreFX/CoreFX.issues.json

index 359837f..f625f6f 100644 (file)
@@ -429,15 +429,21 @@ namespace System
 
         public static bool operator <(Version v1, Version v2)
         {
-            if ((object)v1 == null)
-                throw new ArgumentNullException(nameof(v1));
+            if (v1 is null)
+            {
+                return !(v2 is null);
+            }
+
             return (v1.CompareTo(v2) < 0);
         }
 
         public static bool operator <=(Version v1, Version v2)
         {
-            if ((object)v1 == null)
-                throw new ArgumentNullException(nameof(v1));
+            if (v1 is null)
+            {
+                return true;
+            }
+
             return (v1.CompareTo(v2) <= 0);
         }
 
index cfd18ac..9104e2f 100644 (file)
                 },
                 {
                     "name": "System.Tests.BufferTests.BlockCopy_Invalid",
-                    "reason" : "https://github.com/dotnet/coreclr/pull/23636"
+                    "reason": "https://github.com/dotnet/coreclr/pull/23636"
+                },
+                {
+                    "name": "System.Tests.VersionTests.Comparisons_NullArgument_ThrowsArgumentNullException",
+                    "reason":  "Version was improved to no longer throw from comparison operators"
                 },
             ]
         }