Prevent NullReferenceException for null analysis type. by hubuk · Pull Request #1949 · PowerShell/PSScriptAnalyzer
PR Summary
Many analysis objects here have null Type field value. Not sure whether this is expected. Probably the Undetermined Type should be used instead of null. Anyway, similar precaution means are used in:
| psClass = classes.FirstOrDefault(item => String.Equals(item.Name, details.Type?.FullName, StringComparison.OrdinalIgnoreCase)); |
Creating test for this problem may be hard as the exception is not always being thrown.
PR Checklist
- PR has a meaningful title
- Use the present tense and imperative mood when describing your changes
- Summarized changes
- Change is not breaking
- Make sure all
.cs,.ps1and.psm1files have the correct copyright header - Make sure you've added a new test if existing tests do not effectively test the code changed and/or updated documentation
- This PR is ready to merge and is not Work in Progress.
- If the PR is work in progress, please add the prefix
WIP:to the beginning of the title and remove the prefix when the PR is ready.
- If the PR is work in progress, please add the prefix
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Most of this code was forked from PowerShell's SMA codebase many years ago and not been touched much since. If you've seen an exception coming from this, such a tweak is OK I think and regression risk is small
This was referenced
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters