声纳问题-转换案例应以无条件的“中断”声明结尾

问题描述

我想请您为声纳问题提供帮助。声纳在下面的代码中将案例EQUALS标记为声纳发出鱿鱼:S128。

-Switch的情况应以无条件的“ break”语句结尾。 我认为在这种情况下,我不必添加“ break”语句。 有人能帮我吗?是误报问题吗?

谢谢。

  public boolean causeException(Throwable throwable) {
        Throwable causeException = ExceptionUtils.getRootCause(throwable);
       Map<String,MatchMode> configuration = infoMessage.get(causeException.getClass());
            String message = throwable.getMessage();
            for (String key : configuration.keySet()) {
                MatchMode matchMode = configuration.get(key);
                switch (matchMode) {
                    case EQUALS:
                        if (message.equals(key)) {
                            return true;
                        }
                    case CONTAINS:
                        if (message.contains(key)) {
                            return false;
                        }
                }
            }
        return false;
    }

解决方法

如果您输入的信息不等于密钥,您将陷入失败。您需要添加休息时间来解决此问题:

  public boolean causeException(Throwable throwable) {
        Throwable causeException = ExceptionUtils.getRootCause(throwable);
       Map<String,MatchMode> configuration = infoMessage.get(causeException.getClass());
            String message = throwable.getMessage();
            for (String key : configuration.keySet()) {
                MatchMode matchMode = configuration.get(key);
                switch (matchMode) {
                    case EQUALS:
                        if (message.equals(key)) {
                            return true;
                        }
                        break; // stops fallthrough
                        // With no "break" it would do the CONTAINS block as well
                    case CONTAINS:
                        if (message.contains(key)) {
                            return true;
                        }
                        break; // stops fallthrough
                    default:
                        // just for clarity
                        break;
                }
            }
        return false;
    }

相关问答

错误1:Request method ‘DELETE‘ not supported 错误还原:...
错误1:启动docker镜像时报错:Error response from daemon:...
错误1:private field ‘xxx‘ is never assigned 按Alt...
报错如下,通过源不能下载,最后警告pip需升级版本 Requirem...