NonEmptyCaseWithoutBreak is reported - existing returns are not seen by SonarQube


(Thomas Stihl) #1
  • versions used (SonarQube Version 7.2.1 (build 14109), Scanner

SonarQube reported:
End this switch case with an unconditional break, continue, return or throw statement.

In my opnion there is return statement in any case but it is not found by SonarQube.

 switch (Operation)
    case WRITE_IN_VALID_PAGE: /* ---- Write operation ---- */
      if (pagestatus1 == VALID_PAGE)
        /* Page0 receiving data */
        return ((pagestatus0 == RECEIVE_DATA) ? PAGE0 : PAGE1);
        if (pagestatus0 == VALID_PAGE)
        /* Page1 receiving data */
        return ((pagestatus1 == RECEIVE_DATA) ? PAGE1 : PAGE0);
        return NO_VALID_PAGE; /* No valid Page */
    case READ_FROM_VALID_PAGE: /* ---- Read operation ---- */

(G Ann Campbell) #2


Could you clarify by specifying which language this is from?


(Thomas Stihl) #3


it is ‘C’ code.


(Loïc Joly) #4

Hello Thomas,

This rule is specified according to the Misra standard, and it behaves as expected in this standard:

An unconditional break statement shall terminate every switch-clause

We agree that it may seem a little bit too strict, because code such as the one you presented cannot fall through to the next case. We might revisit this rule in future versions, but nothing is written in stone yet.