From b0b4886b402b815f71e5728bed653151a240348f Mon Sep 17 00:00:00 2001 From: Dongbo Wang Date: Tue, 14 Feb 2023 11:20:31 -0800 Subject: [PATCH] Revert a few change to not use 'ArgumentNullException.ThrowIfNull' --- src/System.Management.Automation/engine/Utils.cs | 9 +-------- .../engine/lang/scriptblock.cs | 7 ++++--- .../engine/parser/SafeValues.cs | 7 ++++--- .../namespaces/FileSystemProvider.cs | 1 + .../utils/ParserException.cs | 4 +--- .../utils/perfCounters/CounterSetRegistrarBase.cs | 4 +--- 6 files changed, 12 insertions(+), 20 deletions(-) diff --git a/src/System.Management.Automation/engine/Utils.cs b/src/System.Management.Automation/engine/Utils.cs index bdf85b54e5e..74e3e468246 100644 --- a/src/System.Management.Automation/engine/Utils.cs +++ b/src/System.Management.Automation/engine/Utils.cs @@ -1733,11 +1733,6 @@ internal ReadOnlyBag(HashSet hashset) /// internal static class Requires { - internal static void NotNull(object value, string paramName) - { - ArgumentNullException.ThrowIfNull(value, paramName); - } - internal static void NotNullOrEmpty(string value, string paramName) { if (string.IsNullOrEmpty(value)) @@ -1748,9 +1743,7 @@ internal static void NotNullOrEmpty(string value, string paramName) internal static void NotNullOrEmpty(ICollection value, string paramName) { - ArgumentNullException.ThrowIfNull(value, paramName); - - if (value.Count == 0) + if (value is null || value.Count == 0) { throw new ArgumentNullException(paramName); } diff --git a/src/System.Management.Automation/engine/lang/scriptblock.cs b/src/System.Management.Automation/engine/lang/scriptblock.cs index c00fb9d6e37..fdc5bcdb326 100644 --- a/src/System.Management.Automation/engine/lang/scriptblock.cs +++ b/src/System.Management.Automation/engine/lang/scriptblock.cs @@ -1138,9 +1138,10 @@ public void Begin(bool expectInput, EngineIntrinsics contextToRedirectTo) /// The command you're calling this from (i.e. instance of PSCmdlet or value of $PSCmdlet variable). public void Begin(InternalCommand command) { - ArgumentNullException.ThrowIfNull(command); - - ArgumentNullException.ThrowIfNull(command.MyInvocation, nameof(command)); + if (command is null || command.MyInvocation is null) + { + throw new ArgumentNullException(nameof(command)); + } Begin(command.MyInvocation.ExpectingInput, command.commandRuntime); } diff --git a/src/System.Management.Automation/engine/parser/SafeValues.cs b/src/System.Management.Automation/engine/parser/SafeValues.cs index f551270c372..05c87daab5b 100644 --- a/src/System.Management.Automation/engine/parser/SafeValues.cs +++ b/src/System.Management.Automation/engine/parser/SafeValues.cs @@ -530,10 +530,11 @@ public object VisitIndexExpression(IndexExpressionAst indexExpressionAst) // Get the value of the index and value and call the compiler var index = indexExpressionAst.Index.Accept(this); var target = indexExpressionAst.Target.Accept(this); - - ArgumentNullException.ThrowIfNull(index, nameof(indexExpressionAst)); - ArgumentNullException.ThrowIfNull(target, nameof(indexExpressionAst)); + if (index is null || target is null) + { + throw new ArgumentNullException(nameof(indexExpressionAst)); + } return GetIndexedValueFromTarget(target, index); } diff --git a/src/System.Management.Automation/namespaces/FileSystemProvider.cs b/src/System.Management.Automation/namespaces/FileSystemProvider.cs index 5c2ff6d89c4..30db2e27180 100644 --- a/src/System.Management.Automation/namespaces/FileSystemProvider.cs +++ b/src/System.Management.Automation/namespaces/FileSystemProvider.cs @@ -7969,6 +7969,7 @@ internal static bool CreateJunction(string path, string target) { throw new ArgumentNullException(nameof(target)); } + using (SafeHandle handle = WinOpenReparsePoint(path, FileAccess.Write)) { byte[] mountPointBytes = Encoding.Unicode.GetBytes(NonInterpretedPathPrefix + Path.GetFullPath(target)); diff --git a/src/System.Management.Automation/utils/ParserException.cs b/src/System.Management.Automation/utils/ParserException.cs index 9087c374b69..4070fa7e7f1 100644 --- a/src/System.Management.Automation/utils/ParserException.cs +++ b/src/System.Management.Automation/utils/ParserException.cs @@ -129,9 +129,7 @@ public ParseException(string message, /// The collection of error messages. public ParseException(ParseError[] errors) { - ArgumentNullException.ThrowIfNull(errors); - - if (errors.Length == 0) + if (errors is null || errors.Length == 0) { throw new ArgumentNullException(nameof(errors)); } diff --git a/src/System.Management.Automation/utils/perfCounters/CounterSetRegistrarBase.cs b/src/System.Management.Automation/utils/perfCounters/CounterSetRegistrarBase.cs index 33e03e67a47..f9a08b76a87 100644 --- a/src/System.Management.Automation/utils/perfCounters/CounterSetRegistrarBase.cs +++ b/src/System.Management.Automation/utils/perfCounters/CounterSetRegistrarBase.cs @@ -108,9 +108,7 @@ protected CounterSetRegistrarBase( CounterSetInstType = counterSetInstType; CounterSetName = counterSetName; - ArgumentNullException.ThrowIfNull(counterInfoArray); - - if (counterInfoArray.Length == 0) + if (counterInfoArray is null || counterInfoArray.Length == 0) { throw new ArgumentNullException(nameof(counterInfoArray)); }