diff --git a/Analyzers/Analyzers/SecureIO/FileOperationAnalyzer.cs b/Analyzers/Analyzers/SecureIO/FileOperationAnalyzer.cs index 64ae8e5..ebbcfd1 100644 --- a/Analyzers/Analyzers/SecureIO/FileOperationAnalyzer.cs +++ b/Analyzers/Analyzers/SecureIO/FileOperationAnalyzer.cs @@ -238,7 +238,7 @@ private static IEnumerable GetPathArgumentsFromObjectCreation( var objectCreationWitinVariableDeclarator = variableDeclaratorMatchingMemberAccess .DescendantNodes(descendIntoChildren: node => node.ChildNodes().Any()) .OfType() - .First(); + .FirstOrDefault(); if (objectCreationWitinVariableDeclarator is null) { @@ -443,13 +443,13 @@ private static List GetFileOperationLocationsToAnalyze( // Cases where the path argument was not added to the locations to analyze => assume the first position of the block if (!locationsToAnalyze.Exists(locationToAnalyze => locationToAnalyze.PathArgumentName == pathArgumentName)) { - var firstPosition = descendantNodes.First(); + var firstPosition = descendantNodes.FirstOrDefault(); if (firstPosition == null) { continue; } - locationsToAnalyze.Add(new LocationToAnalyze(descendantNodes.First().GetLocation(), pathArgumentName)); + locationsToAnalyze.Add(new LocationToAnalyze(firstPosition.GetLocation(), pathArgumentName)); } }