使用 switch(String) 时,声纳看不到默认情况
使用jdk 1.7(这样我可以使用字符串开关和multicatch)
通过声纳运行我的代码时,我收到以下消息:
switch (extension) {
Switch语句发现默认情况下丢失
我理解它的意思,但它不正确,请参阅下面的代码: 为什么我会收到此错误。
private void handlefileformats(String location) {
try {
String extension = location.substring(location.length() - 4);
switch (extension) {
case ".xml":
logger.info(LoggerMessages.getLoadxml());
break;
case ".txt":
case ".csv":
logger.info(LoggerMessages.getLoadcsv());
break;
default:
throw new IncorrectFileException(location, sets);
}
} catch (IOException || IncorrectFileExceptione) {
logger.fatal(LoggerMessages.getException(), e);
return null;
}
}
ps 上面的代码是原始代码的简化版本,这就是为什么我不使用 else if 的原因。
提前致谢
using jdk 1.7 (so i can use String switches and the multicatch)
when running my code through sonar i got the following message:
switch (extension) {
Switch statement found where default case is missing
i understand what its saying but it is not right see my code below:
Why am i getting this error.
private void handlefileformats(String location) {
try {
String extension = location.substring(location.length() - 4);
switch (extension) {
case ".xml":
logger.info(LoggerMessages.getLoadxml());
break;
case ".txt":
case ".csv":
logger.info(LoggerMessages.getLoadcsv());
break;
default:
throw new IncorrectFileException(location, sets);
}
} catch (IOException || IncorrectFileExceptione) {
logger.fatal(LoggerMessages.getException(), e);
return null;
}
}
p.s. the code above is a simplified version of the original thats why i do not use the else if.
thanks in advance
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
事实上,Sonar 2.12 将支持 Java7。
Indeed Java7 will be supported in Sonar 2.12.