I run popular Java Code Quality tool SonarQube and was observing its suggestions. I see that it reported below issue with 'Major' severity,

enter image description here

You could see compliant and non-compliant piece of code for that rule as below,

  if(something) {
    executeTask();
  } else if (somethingElse) {          // **Compliant**
    doSomethingElse();
  }
  else {                               // **Noncompliant**
     generateError();
  }

I feel that, it is developer's discretion and at least that issue should not be reported with 'Major' severity. ('Minor' or 'Info' severity could be fine with proper justification.)

Do you have any justification about why such recommendation?

Secondly, the question to the audience who are dealing with code quality tools for some considerable time, overall how serious I need to be with code quality tool?

(I found some articles, here and here, that actually endorses the 'Non Compliant' way of writing if-else or try-catch-finally.)

2

There are 2 best solutions below

2
On BEST ANSWER

It's not surprising that your code is treated as non-compliant - it violates Java Code Conventions. It's up to you to follow code conventions or not, but consider the fact that code written in common style is much more easier to understand.

According to the Java Code Conventions if-else statements should have the following form:

if (condition) {
    statements;
} else {
    statements;
}

And try-catch statements should have the following format:

try {
    statements;
} catch (ExceptionClass e) {
    statements;
}
0
On

If you don't want to bother with code conventions such as this one, you can disable the rule from your quality profile - or even change its severity. The default "SonarQube Way" quality profile is only an indication of widely accepted best practice, but ultimately it's your responsibility to adapt it to your needs.