Description
IntraJ’s Empty While Loop Body analysis is a code smell detection can help you identify empty while loop bodies in your Java code. Empty while loop 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 x = 10;
if (x > 5) {
// Empty statement
} else {
// Empty statement
}
}
}
In this code, the if
statement has empty bodies for both the then and else clauses. 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.
Example Error 2
Consider the following Java code:
public class Example {
public static void main(String[] args) {
int x = 10;
if (bar(x));{
//Do something
}
return;
}
}
How IntraJ Detects Empty While-Loop
s
IntraJ’s Empty If Statement Body analysis detects empty if statement bodies by analyzing the syntax of the code. Specifically, it looks for cases where an if
statement has an empty body for either the then
or else
clause.
In the example above, IntraJ would identify that both the then
and else
clauses of the if statement have empty bodies, and would flag it as an empty if statement body code smell.
–
Analyisis id: EMPTYIF