From 35d7e1560fd4efdd5829b6e3fccc0932d923d617 Mon Sep 17 00:00:00 2001 From: Stephen Toub Date: Thu, 11 Apr 2019 20:47:35 -0400 Subject: [PATCH] Fix Version's comparer operators to allow null (#23898) 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 | 14 ++++++++++---- tests/CoreFX/CoreFX.issues.json | 6 +++++- 2 files changed, 15 insertions(+), 5 deletions(-) diff --git a/src/System.Private.CoreLib/shared/System/Version.cs b/src/System.Private.CoreLib/shared/System/Version.cs index 359837f..f625f6f 100644 --- a/src/System.Private.CoreLib/shared/System/Version.cs +++ b/src/System.Private.CoreLib/shared/System/Version.cs @@ -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); } diff --git a/tests/CoreFX/CoreFX.issues.json b/tests/CoreFX/CoreFX.issues.json index cfd18ac..9104e2f 100644 --- a/tests/CoreFX/CoreFX.issues.json +++ b/tests/CoreFX/CoreFX.issues.json @@ -1357,7 +1357,11 @@ }, { "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" }, ] } -- 2.7.4