Methods Named 'is…' Should Return Boolean
ID |
java.naming_is_boolean_return |
Severity |
low |
Remediation Complexity |
trivial |
Remediation Risk |
medium |
Remediation Effort |
low |
Resource |
Naming Convention |
Language |
Java |
Tags |
naming |
Description
Reports methods whose names start with is that do not return boolean. The is prefix is a well-established convention for boolean queries.
Rationale
When a developer reads isReady(), they expect a yes/no answer. Returning int, String, or another non-boolean type violates this expectation, causing confusion and subtle bugs at call sites.
// Bad — name implies boolean but returns int
public int isOK() {
return _value;
}
// Good — rename to reflect actual return type
public int getValue() {
return _value;
}
Remediation
Either change the return type to boolean, or rename the method to drop the is prefix and use a name that reflects the actual return type (e.g., getXxx).