Potential null dereference
V3080 Possible null dereference. Consider inspecting ‘ItemSelectionCondition’. System.Management.Automation displayDescriptionData_List.cs 352
internal bool SafeForExport() { return DisplayEntry.SafeForExport() && ItemSelectionCondition == null || ItemSelectionCondition.SafeForExport(); }
There is a risk of getting a NullReferenceException when executing this code. The ItemSelectionCondition.SafeForExport() subexpression will be evaluated only if the first subexpression evaluates to false. Therefore, if DisplayEntry.SafeForExport() returns false and ItemSelectionCondition == null, the second subexpression, ItemSelectionCondition.SafeForExport(), will be evaluated, and that’s where the null dereference will occur (and raise the exception). Correct variant can be like this:
internal bool SafeForExport() { return (DisplayEntry.SafeForExport() && ItemSelectionCondition == null) || (ItemSelectionCondition != null && ItemSelectionCondition.SafeForExport()); }
Please click here to see more bugs from this project.