使用 switch(String) 时,声纳看不到默认情况

发布于 2024-12-18 03:57:32 字数 918 浏览 2 评论 0原文

使用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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

好久不见√ 2024-12-25 03:57:33

事实上,Sonar 2.12 将支持 Java7。

Indeed Java7 will be supported in Sonar 2.12.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文