From e92237ce0448c3e69739e0b70b22f5773288baff Mon Sep 17 00:00:00 2001 From: Wessel <78801719+WesHaze@users.noreply.github.com> Date: Sat, 15 Mar 2025 15:01:36 +0100 Subject: [PATCH] Move null guard statement up in NuGetComponentDetector.IsValidPath to avoid uncessary throw of ArgumentNullException in FileInfo constructor --- .../nuget/NuGetComponentDetector.cs | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/Microsoft.ComponentDetection.Detectors/nuget/NuGetComponentDetector.cs b/src/Microsoft.ComponentDetection.Detectors/nuget/NuGetComponentDetector.cs index eba09e5c7..f852b43f8 100644 --- a/src/Microsoft.ComponentDetection.Detectors/nuget/NuGetComponentDetector.cs +++ b/src/Microsoft.ComponentDetection.Detectors/nuget/NuGetComponentDetector.cs @@ -254,6 +254,11 @@ private IList GetRepositoryPathsFromNugetConfig(IComponentStream /// True if path is valid, otherwise it retuns false. private bool IsValidPath(string potentialPath) { + if (potentialPath == null) + { + return false; + } + FileInfo fileInfo = null; try @@ -265,11 +270,6 @@ private bool IsValidPath(string potentialPath) return false; } - if (potentialPath == null) - { - return false; - } - return fileInfo.Exists || fileInfo.Directory.Exists; } }