Literal "false" boolean value - false positive?

Observed with SonarQube Developer Edition v8.1 with Java 8:

return alpha.getValue() != null && alpha.getValue().getIndent() != null ? alpha.getValue().getIndent().isNow() : false

This is triggering the rule squid:S1125 “Boolean literals should not be redundant”. I believe this is a false positive code smell. The ternary operator requires a false return value.

In the “Compliant Solution” section of the rule description there is an example of how you can rewrite your code to make it compliant.
A ternary test() ? epxr : false evaluates to true if (test() ∧ expr) and to false in all other cases. So you could simply write

return alpha.getValue() != null && alpha.getValue().getIndent() != null && alpha.getValue().getIndent().isNow();
1 Like