Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix several user reported issue NullReferenceException #2596

Merged
merged 5 commits into from
Dec 28, 2022
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/ReleaseHistory.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
* BUGFIX: Fix classes inside NotYetAutoGenerated folder missing `virtual` keyword for public methods and properties, by regenerate and manually sync the changes. [#2537](https://github.com/microsoft/sarif-sdk/pull/2537)
* FEATURE: Allow external set of `MaxFileSizeInKilobytes`, which will allow SDK users to change the value. (Default value is 1024) [#2578](https://github.com/microsoft/sarif-sdk/pull/2578)
* BUGFIX: MSBuild Converter now accepts case insensitive keywords and supports PackageValidator msbuild log output. [#2579](https://github.com/microsoft/sarif-sdk/pull/2579)
* BUGFIX: Eliminate `NullReferenceException` when file hashing fails (due to file locked or other errors reading the file). [#2596](https://github.com/microsoft/sarif-sdk/pull/2596)

## **v3.1.0** [Sdk](https://www.nuget.org/packages/Sarif.Sdk/3.1.0) | [Driver](https://www.nuget.org/packages/Sarif.Driver/3.1.0) | [Converters](https://www.nuget.org/packages/Sarif.Converters/3.1.0) | [Multitool](https://www.nuget.org/packages/Sarif.Multitool/3.1.0) | [Multitool Library](https://www.nuget.org/packages/Sarif.Multitool.Library/3.1.0)

Expand Down
10 changes: 5 additions & 5 deletions src/Sarif.Driver/Sdk/MultithreadedAnalyzeCommandBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -513,11 +513,11 @@ private async Task<bool> HashFilesAndPutInAnalysisQueueAsnc()

loggerCache ??= new Dictionary<string, CachingLogger>();

if (!loggerCache.TryGetValue(hashData.Sha256, out CachingLogger logger))
{
logger = loggerCache[hashData.Sha256] = (CachingLogger)context.Logger;
}
context.Logger = logger;
context.Logger = hashData?.Sha256 == null
? (CachingLogger)context.Logger
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

? (CachingLogger)context.Logger

if no hash, have to set the context.Logger to itself? can we skip in this case?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, let's just wrap this code in a check that hashData.Sha256 is non-null, will be more readable.

Could we get this change in and then also try to mock up a test for this condition?

I'm concerned we're not necessarily handling this negative condition comprehensively.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we get this change in and then also try to mock up a test for this condition? ---- done fixing the code, will need to mock up a test.

: loggerCache.TryGetValue(hashData.Sha256, out CachingLogger logger)
? logger
: (loggerCache[hashData.Sha256] = (CachingLogger)context.Logger);
}

await readyToScanChannel.Writer.WriteAsync(index);
Expand Down