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

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

      2. SONAR 抱怨改变条件,使其并不总是评估为“假".

        SONAR complaining to change the condition so that it does not always evaluate to quot;falsequot;(SONAR 抱怨改变条件,使其并不总是评估为“假.)

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

                <bdo id='rR2My'></bdo><ul id='rR2My'></ul>
                  <tbody id='rR2My'></tbody>

                  <tfoot id='rR2My'></tfoot>

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

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

                2. 本文介绍了SONAR 抱怨改变条件,使其并不总是评估为“假".的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  public String generateURLSafeToken(String username, char[] password) throws CredentialTokenException {this.tokenValid = false;字符串令牌 = null;if ((username.length() < 1) || (username == null)) {throw new CredentialTokenException("用户名不能为空字符串或 null.");}if ((password.length < 1) || (password == null)) {throw new CredentialTokenException("密码不能为空或 null.");}

                  <块引用>

                  我在第 4 行和第 7 行遇到此错误(用户名 == null 和密码 == null)

                  我的代码中需要这部分.我正在尝试 isEmpty() 而不是 null 但也面临着问题.解决此 SONAR 错误的替代方法或解决方案是什么

                  解决方案

                  总是计算结果为 false 的条件是 username == nullpassword ==空.

                  我们以username为例.运算符 || 是 短路 意味着它赢了'如果左侧为 true,则不计算右侧.基本上有两种情况:

                  • 给定的 username 不是 null.条件 username.length() <1 被评估
                    • 如果结果为true,我们直接返回,进入if分支
                    • 如果结果是 false,我们会尝试评估 username == null.但是由于给出的 username 不是 null,因此 always 的计算结果为 false.
                  • 给定的 usernamenull.条件 username.length() <1 被评估.这实际上停在那里:它会抛出一个 NullPointerException 并且不会评估右侧.

                  因此,您可以看到,无论何时实际评估 username == null 条件,结果始终为 false.这就是 SonarQube 警告告诉您的内容.

                  这里的解决方案是颠倒您的 2 个条件.考虑拥有

                  if (username == null || username.length() < 1)

                  相反.如果您重新开始并检查每个案例,您会注意到没有一个表达式将始终具有相同的结果:

                  • 给定的 username 不是 null.第一个条件明确评估为 false,第二个条件被评估,可能返回 truefalse.
                  • 给定的 usernamenull.第一个条件明确评估为 true 和短路.

                  public String generateURLSafeToken(String username, char[] password) throws CredentialTokenException {
                      this.tokenValid = false;
                  
                      String token = null;
                      if ((username.length() < 1) || (username == null)) {
                          throw new CredentialTokenException("Username cannot be an empty string or null.");
                      }
                      if ((password.length < 1) || (password == null)) {
                          throw new CredentialTokenException("Password cannot be an empty or null.");
                      }
                  

                  I am facing this error in line 4 and line 7 (username == null and password == null)

                  And I need this part in my code. I am trying isEmpty() instead of null but facing problems in that also . What is an alternate way or the solution to fix this SONAR error

                  解决方案

                  The conditions which always evaluates to false are username == null and password == null.

                  Let's take the example of username. The operator || is short-circuiting meaning it won't evaluate the right hand side if the left hand side is true. Basically, there are 2 cases:

                  • The username given is not null. The condition username.length() < 1 is evaluated
                    • If the result is true, we return directly and enter the if branch
                    • If the result is false, we try to evaluate username == null. But since the username given is not null, this always evaluate to false.
                  • The username given is null. The condition username.length() < 1 is evaluated. This actually stops right there: it will throw a NullPointerException and will not evaluate the right hand side.

                  Therefore, you can see that whenever the username == null condition was actually evaluated, the result was always false. This is what the SonarQube warning is telling you.

                  The solution here is to reverse your 2 conditions. Consider having

                  if (username == null || username.length() < 1)
                  

                  instead. If you start over and go through each case, you'll notice that none of the expressions will always have the same result:

                  • The username given is not null. First condition clearly evaluates to false and the second is evaluated, which may return true or false.
                  • The username given is null. The first condition clearly evaluated to true and short-circuits.

                  这篇关于SONAR 抱怨改变条件,使其并不总是评估为“假".的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

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

                  相关文档推荐

                  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 等)
                  <i id='JlMZk'><tr id='JlMZk'><dt id='JlMZk'><q id='JlMZk'><span id='JlMZk'><b id='JlMZk'><form id='JlMZk'><ins id='JlMZk'></ins><ul id='JlMZk'></ul><sub id='JlMZk'></sub></form><legend id='JlMZk'></legend><bdo id='JlMZk'><pre id='JlMZk'><center id='JlMZk'></center></pre></bdo></b><th id='JlMZk'></th></span></q></dt></tr></i><div id='JlMZk'><tfoot id='JlMZk'></tfoot><dl id='JlMZk'><fieldset id='JlMZk'></fieldset></dl></div>

                        <tfoot id='JlMZk'></tfoot>

                          <tbody id='JlMZk'></tbody>
                        1. <small id='JlMZk'></small><noframes id='JlMZk'>

                            <bdo id='JlMZk'></bdo><ul id='JlMZk'></ul>
                            <legend id='JlMZk'><style id='JlMZk'><dir id='JlMZk'><q id='JlMZk'></q></dir></style></legend>