I can't really figure out why Sonar keeps complaining about the fact that I "don't have a break statement" even if it's not needed..
My switch:
public static String lookupVoyageId(String referenceNumber, String sender) {
switch (sender) {
case "400_HGENT":
case "200_HAPEN":
case "500_HOOST":
Preconditions.checkArgument(referenceNumber.contains("-"));
return referenceNumber.split("-")[0];
case "600_HZEEB":
Preconditions.checkArgument(referenceNumber.length() >= 6);
return referenceNumber.substring(0, 6);
case "800_BVL":
throw new TransferException("This reference number for IBIS isn't according to the requirements. Can't implement it yet.");
case "MCCD":
throw new TransferException("This reference number for MCCD isn't according to the requirements. Can't implement it yet.");
default:
throw new TransferException("The sender (" + sender + ") couldn't be identified.");
}
}
and sonar keeps giving me the critical: "A switch statement does not contain a break"
Why is this? I don't need any breaks in this switch?
I know it might be a specific case, but I can't find anything on the web.
If you can't decrease the number of switch case or can't refactor the code you can suppress the warning with
@SuppressWarnings({"squid:S128", "squid:S1479"}
Sample usage here
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With