Menu

#1218 TooFewBranchesForASwitchStatement misprioritized

PMD-5.1.2
closed
PMD
5-Trivial
Bug
5.1.1
2014-07-20
2014-07-01
No

The priority for java-design/TooFewBranchesForASwitchStatement is 1, the highest priority. The description suggests it is a matter of being confusing, not of necessarily being buggy (which makes sense since a switch statement can be functionally equivalent to an if-else branch). The PMD documentation's recommendation here: http://pmd.sourceforge.net/pmd-5.1.1/rule-guidelines.html suggests this should be 3 (or perhaps 4, depending on how severely confusing this issue is considered), while suggesting 1 for "broken or critically buggy" and "change absolutely required", niether of which can be true if a switch equivalent to an if-else branch is still functionally valid and quite possibly functionally correct.

(FWIW, I ran into this one with some factory-like placeholder code where the value a switch acted upon needs to be able to have more cases added in the future, but does not currently have more than a couple. I don't consider the warning altogether invalid, as a warning, even in such a case where I ultimately consider the switch more semantic than an if-else despite few current cases; I just want to be able to filter it out by priority rather than only by explicitly marking that statement to be ignored by PMD.)

Discussion

  • Andreas Dangel

    Andreas Dangel - 2014-07-12

    I agree with your assessment. I changed the priority of this rule to 3 for the next release.

     
  • Andreas Dangel

    Andreas Dangel - 2014-07-12
    • status: open --> closed
    • assigned_to: Andreas Dangel
    • Milestone: New Tickets --> PMD-Next
     

Log in to post a comment.