SonarLint : Java - Collapsible "if" statements should be merged (squid:S1066)

SonarLint : Java - Collapsible "if" statements should be merged (squid:S1066)

in some cases are multiple if statement whereas both the if statement can be merged together , so collapsible if statement should be merged it will improve the readability and maintainability of the codebase.

Non Compliant Code

image.png

Compliant Code

screenshot_15.png

Example from sonar Source

Noncompliant Code Example

if (file != null) {
  if (file.isFile() || file.isDirectory()) {
    /* ... */
  }
}

Compliant Solution

if (file != null && isFileOrDirectory(file)) {
  /* ... */
}

private static boolean isFileOrDirectory(File file) {
  return file.isFile() || file.isDirectory();
}