S1905 - False Positives generated within c# ternary operator statement

The analyzer generates “warning S1125: Remove the unnecessary Boolean literal(s).” on the line of code for the ‘required’ boolean assignment. In the code snippet below, ‘item’ object is an optional (can be null) ‘to be cloned’ item of DataItem type. Code intent is 'use values from the cloned item, if there is one, otherwise use defaults. ‘titleHtml’ property is of string type (and no warning is generated), ‘required’ is a bool type. Looks like S1905 warning is caused by the first (true) part of the ternary statement, but since 2nd (false) ternary statement is not a ‘true’ literal, the warning really should not be shown.

            var newItem = new Datatem()
                // Skipping code lines ....
                titleHtml = item == null ? string.Empty : item.titleHtml,
                required = item == null ? false : item.required

Hi @garrick_s,

welcome to our community.

I’ve took a short look and as far as I can tell the solution suggested by the code fix provider required = !(item == null) && item.required respects the rule specifications.

Costin - the issue as described is with a false positive on the string assignment line: