A false negative about the rule RSPEC-3400

Hi, I found a false negative about the rule RSPEC-3400. Please read the following code example:

public boolean getTrue() {return true;}  // should report warnings here
public boolean getFalse() {return false;}

It is obvious that these two methods return constant value, but no warnings. Hence, I think they are false negatives. Thanks for your consideration.

Hello @Belle
The original rationale is discussed here, but I would say that the number of possible values is considerably limited compared to other primitive types.
But more importantly, for boolean methods that are meant to be overridden in child classes, returning a default value like this is quite common.

But your example brings up an interesting issue that the rule currently does not consider: the rule should not report on methods that are overridable (we already have a ticket for that).

I added the following ticket as a follow-up to handle booleans.

Cheers,

Dorian

1 Like

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.