Files
openide/java/java-impl/resources/inspectionDescriptions/BooleanParameter.html
Leonid Shalupov 40795fe787 IJI-2422: community/java: move resources under resources root
GitOrigin-RevId: 8b2b63fc6db476ca0c2cfe5cadd84db6c4236d0f
2025-02-05 04:43:28 +00:00

26 lines
1.1 KiB
HTML

<html>
<body>
Reports public methods that accept a <code>boolean</code> parameter.
<p>It's almost always bad practice to add a <code>boolean</code> 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 <code>boolean</code> stands for without looking at
the source or documentation.</p>
<p>This problem is also known as <a href="https://ariya.io/2011/08/hall-of-api-shame-boolean-trap">the boolean trap</a>.
The <code>boolean</code> parameter can often be replaced with an <code>enum</code>.</p>
<p>Example:</p>
<pre><code>
// 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) {
// ...
}
</code></pre>
<!-- tooltip end -->
<p>
Use the <b>Only report methods with multiple boolean parameters</b> option to warn only when a method contains more than one boolean parameter.
<p>
</body>
</html>