Why does IntelliJ IDEA think my Boolean method is always inverted when it is not?

"Always inverted" means that in all places where the method is called, the ! operator is applied to the call expression. IntelliJ IDEA has no clue whether this is hard or easy to reason about from the semantic point of view; it just performs syntactic analysis. If you believe that inverting the method will make the code harder to understand, simply suppress the inspection for this method.


I have a use case where I need a view (android project) whenever an emergency condition is active.

I called this view EmergencyView:

public class EmergencyView extends RelativeLayout {

   private boolean emergencyActive;

...

   public boolean isEmergencyActive() {
      return emergencyActive;
   }
}

In this use case, I get the BooleanMethodIsAlwaysInverted warning for my getter. If I change the getter method's name to isEmergency, the warning goes away so there's a bit more being checked here than just the semantics of the code.

Initially, I went with @SuppressWarnings("BooleanMethodIsAlwaysInverted") to hide this warning, but ultimately I decided to change the name of my field to just be emergency.

The question remains whether "Emergency Active" or simply "Emergency" is the best way to describe the functional state of a View called EmergencyView, but I no longer get this warning nor do I have to suppress it.