◐ Shell
clean mode source ↗

Prevent NullReferenceException for null analysis type. by hubuk · Pull Request #1949 · PowerShell/PSScriptAnalyzer

@hubuk

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

Many analysis objects here have null Type field value. This leads to premature exiting the method.

bergmeister

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

Mar 16, 2024