For the following contrived example (the real code actually makes sense, I promise), Sonarqube 5.3 with Java plugin 2.10 will give me the dreaded “Change this condition so that it does not always evaluate to "true"”:
public String sonarLint(DayOfWeek dow) {
boolean one = false;
boolean two = false;
switch (dow) {
case MONDAY:
one = true;
case TUESDAY:
two = true;
break;
default:
// nothing
}
return one && two ? "yes" : "no";
}
As far as I can see, when dow
is MONDAY
, the condition is true, while it's false otherwise (IntelliJ agrees, BTW, telling me that two
whill always be true when it is evaluated at all). Did I hit a bug in Sonarqube here?
Sonar should report the error for missing break statement as well.
Switch cases should end with an unconditional "break" statement (Squid:S128).
Once you have the break statement in both the cases, then statement will never be executed as true.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.