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

Conversation

shaopeng-gh
Copy link
Collaborator

@shaopeng-gh shaopeng-gh commented Dec 27, 2022

Fix NullReferenceException when file hashing fails (due to file locked or other errors reading the file).

One way to repro:
Scan the root folder and put the output SARIF file inside the folder, the output .sarif file will be locked,
for any reason can’t get hash (locked in this case), hashes will be null and then we will get unhandled null exception.

}
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.

Copy link
Member

@michaelcfanning michaelcfanning left a comment

Choose a reason for hiding this comment

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

:shipit:

@michaelcfanning michaelcfanning enabled auto-merge (squash) December 28, 2022 22:34
@michaelcfanning michaelcfanning merged commit 2f03914 into main Dec 28, 2022
@michaelcfanning michaelcfanning deleted the users/shaopeng-gh/nullreffix branch December 28, 2022 22:40
This was referenced Feb 21, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants