Sonar, S128: Switch cases must end with an unconditional "break" VS continue

The squid: 128 rule seems to exist to prevent failure in the case of a switch unless an expression is explicitly specified. This seems like a reasonable rule of thumb, since this is a missed phrase is a common mistake.

However, failure is entirely justified if desired.

The documentation for this rule states that the only way to fail is by using continue

   case 4:                                // Use of continue statement
   continue;

      

I also checked the source code for SwitchCaseWithoutBreakCheck - this is indeed a progress check for the continue statement.

  @Override
  public void visitContinueStatement(ContinueStatementTree tree) {
    super.visitContinueStatement(tree);
    markSwitchCasesAsCompliant();
  }

      

However, the Java language does not support continuation in switch / case. In addition, online documentation and. / java -checks / src / test / files / checks / SwitchCaseWithoutBreakCheck.java are valid Java programs.

Am I missing something or is this rule completely violated and does not allow the use of failure?

+3


source to share


1 answer


You are perfectly correct in stating that the description here is incorrect, and then you actually have no way of not triggering the rule if you want to actually use the failure (and therefore, you can either mark the problem as false positive in that case, or deactivate the rule alltogether)

calling the rule "broken" is an opinion, so I won't argue about it;)



However, a ticket was created to solve the problem: http://jira.sonarsource.com/browse/SONARJAVA-1169

+2


source







All Articles