Back to Intellij Community

IfStatementWithIdenticalBranches

java/java-impl/resources/inspectionDescriptions/IfStatementWithIdenticalBranches.html

2025.3-rc-2580 B
Original Source

Reports if statements in which common parts can be extracted from the branches.

These common parts are independent from the condition and make if statements harder to understand.

Example:

if (x > 12) {
    doSomethingBefore();
    doSomethingDifferent1();
    doSomethingAfter();
  } else {
    doSomethingBefore();
    doSomethingDifferent2();
    doSomethingAfter();
  }

After the quick-fix is applied:

doSomethingBefore();
  if (x > 12) {
    doSomethingDifferent1();
  } else {
    doSomethingDifferent2();
  }
  doSomethingAfter();

Updated in 2018.1