<i id='eIufj'><tr id='eIufj'><dt id='eIufj'><q id='eIufj'><span id='eIufj'><b id='eIufj'><form id='eIufj'><ins id='eIufj'></ins><ul id='eIufj'></ul><sub id='eIufj'></sub></form><legend id='eIufj'></legend><bdo id='eIufj'><pre id='eIufj'><center id='eIufj'></center></pre></bdo></b><th id='eIufj'></th></span></q></dt></tr></i><div id='eIufj'><tfoot id='eIufj'></tfoot><dl id='eIufj'><fieldset id='eIufj'></fieldset></dl></div>
      • <bdo id='eIufj'></bdo><ul id='eIufj'></ul>

        <legend id='eIufj'><style id='eIufj'><dir id='eIufj'><q id='eIufj'></q></dir></style></legend>

        <small id='eIufj'></small><noframes id='eIufj'>

        <tfoot id='eIufj'></tfoot>
      1. SonarQube 抱怨:记录或重新抛出此异常

        SonarQube complains: Either log or rethrow this exception(SonarQube 抱怨:记录或重新抛出此异常)
        <i id='y5ujt'><tr id='y5ujt'><dt id='y5ujt'><q id='y5ujt'><span id='y5ujt'><b id='y5ujt'><form id='y5ujt'><ins id='y5ujt'></ins><ul id='y5ujt'></ul><sub id='y5ujt'></sub></form><legend id='y5ujt'></legend><bdo id='y5ujt'><pre id='y5ujt'><center id='y5ujt'></center></pre></bdo></b><th id='y5ujt'></th></span></q></dt></tr></i><div id='y5ujt'><tfoot id='y5ujt'></tfoot><dl id='y5ujt'><fieldset id='y5ujt'></fieldset></dl></div>
          <bdo id='y5ujt'></bdo><ul id='y5ujt'></ul>

              <tbody id='y5ujt'></tbody>
            • <small id='y5ujt'></small><noframes id='y5ujt'>

              <tfoot id='y5ujt'></tfoot>
              • <legend id='y5ujt'><style id='y5ujt'><dir id='y5ujt'><q id='y5ujt'></q></dir></style></legend>
                1. 本文介绍了SonarQube 抱怨:记录或重新抛出此异常的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  在将代码与 Maven 集成后,我正在运行 SonarQube 5 进行代码质量检查.

                  I am running SonarQube 5 for code quality check after integrating the code with Maven.

                  Sonar 抱怨我应该:

                  Sonar is complaining that I should:

                  记录或重新抛出此异常.

                  Either log or rethrow this exception.

                  在以下代码中:

                  public static Date convertStringtoDate(String stringDate) {
                      stringDate = StringUtils.trimToNull(stringDate);
                      SimpleDateFormat dfm = new SimpleDateFormat("dd-MMM-yyyy");
                      Date date = null;
                  
                      if (stringDate != null) {
                          try {
                              date = dfm.parse(stringDate);
                          } catch (Exception e) {
                              logger.info("Cannot convert String to Date: ",convertStringtoDate(e.getMessage()));
                          }
                      }
                  
                      return date;    
                  }
                  

                  我在这里错过了什么?

                  推荐答案

                  首先,这种行为正确吗?您也尝试在异常消息上调用 convertStringtoDate 似乎有点奇怪.

                  First of all, is this behaviour correct? Seems a bit weird that you are trying to call convertStringtoDate on the exception message as well.

                  其次,我最近在使用 Sonar 时遇到了同样的问题.似乎您需要将整个异常作为参数传递给记录器,而不是 e.getMessage() 让 Sonar 意识到您正在记录异常.

                  Secondly, I had the same problem with Sonar recently. Seems like you need to pass the whole exception as a parameter to the logger, instead of e.getMessage() for Sonar to realize you are logging the exception.

                  试试这个:

                  public static Date convertStringtoDate(String stringDate){
                      stringDate = StringUtils.trimToNull(stringDate);
                      SimpleDateFormat dfm = new SimpleDateFormat("dd-MMM-yyyy");
                      Date date = null;
                      if(stringDate!=null){
                          try {
                              date = dfm.parse(stringDate);
                          } catch (Exception e) {
                              logger.info("Cannot convert String to Date: ", e);
                          }
                      }
                      return date;    
                  }
                  

                  这篇关于SonarQube 抱怨:记录或重新抛出此异常的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  Slf4j LoggerFactory.getLogger and sonarqube(Slf4j LoggerFactory.getLogger 和 sonarqube)
                  Security - Array is stored directly(安全性 - 数组直接存储)
                  SonarQube quot;Class Not Foundquot; during Main AST Scan(SonarQube“找不到类在主 AST 扫描期间)
                  Integrate Spock#39;s test with Sonar(将 Spock 的测试与声纳集成)
                  How do I make Hudson/Jenkins fail if Sonar thresholds are breached?(如果违反声纳阈值,我如何让 Hudson/Jenkins 失败?)
                  automatically add curly brackets to all if/else/for/while etc. in a java code-base(自动将大括号添加到 java 代码库中的所有 if/else/for/while 等)

                      <tbody id='26OOL'></tbody>
                        • <bdo id='26OOL'></bdo><ul id='26OOL'></ul>

                            <tfoot id='26OOL'></tfoot>

                            <legend id='26OOL'><style id='26OOL'><dir id='26OOL'><q id='26OOL'></q></dir></style></legend>
                            <i id='26OOL'><tr id='26OOL'><dt id='26OOL'><q id='26OOL'><span id='26OOL'><b id='26OOL'><form id='26OOL'><ins id='26OOL'></ins><ul id='26OOL'></ul><sub id='26OOL'></sub></form><legend id='26OOL'></legend><bdo id='26OOL'><pre id='26OOL'><center id='26OOL'></center></pre></bdo></b><th id='26OOL'></th></span></q></dt></tr></i><div id='26OOL'><tfoot id='26OOL'></tfoot><dl id='26OOL'><fieldset id='26OOL'></fieldset></dl></div>
                          1. <small id='26OOL'></small><noframes id='26OOL'>