Description
IntraJ’s Empty If Statement Body analysis is a code smell detection that can help you identify empty if statement bodies in your Java code. Empty if statement bodies are code smells because they can lead to confusion, mistakes, and bugs.
Example Error 1
Consider the following Java code:
public class Example {
public static void main(String[] args) {
int i = 0;
while (i < 5);{
// Do something
}
return;
}
}
In this code, the while loop has a semicolon after the condition. The semicolon terminates the loop statement, making the body of the while loop an empty statement. This can be confusing for other developers who may be reading the code, and can also lead to mistakes or bugs if the code is modified later.
How IntraJ Detects Empty If-Statement
s
IntraJ’s Empty While Loop Body analysis detects empty while loop bodies by analyzing the syntax of the code. Specifically, it looks for cases where a while
loop has an empty body because of a semicolon after the condition.
In the example above, IntraJ would identify that the body of the while
loop is empty because of the semicolon after the condition, and would flag it as an empty while loop body code smell.
–
Analyisis id: EMPTYWHILE