Inspectopedia Help

'public' method with 'boolean' parameter

Reports public methods that accept a boolean parameter.

It's almost always bad practice to add a boolean parameter to a public method (part of an API) if that method is not a setter. When reading code using such a method, it can be difficult to decipher what the boolean stands for without looking at the source or documentation.

This problem is also known as the boolean trap. The boolean parameter can often be replaced with an enum.


// Warning: it's hard to understand what the // boolean parameters mean when looking at // a call to this method public boolean setPermission(File f, int access, boolean enable, boolean ownerOnly) { // ... }

Use the Only report methods with multiple boolean parameters option to warn only when a method contains more than one boolean parameter.

Inspection options




Only report methods with multiple boolean parameters



Inspection Details

Available in:

IntelliJ IDEA 2023.3, Qodana for JVM 2023.3


Java, 233.SNAPSHOT

Last modified: 13 July 2023