<small id='7zWcx'></small><noframes id='7zWcx'>

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

    2. <legend id='7zWcx'><style id='7zWcx'><dir id='7zWcx'><q id='7zWcx'></q></dir></style></legend>
      <tfoot id='7zWcx'></tfoot>

    3. 声纳错误条件不应无条件地评估为“真".或“错误";

      Sonar error Conditions should not unconditionally evaluate to quot;TRUEquot; or to quot;FALSEquot;(声纳错误条件不应无条件地评估为“真.或“错误;)
      <legend id='IqIOK'><style id='IqIOK'><dir id='IqIOK'><q id='IqIOK'></q></dir></style></legend>

          <bdo id='IqIOK'></bdo><ul id='IqIOK'></ul>

          • <small id='IqIOK'></small><noframes id='IqIOK'>

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

                <tbody id='IqIOK'></tbody>
              1. 本文介绍了声纳错误条件不应无条件地评估为“真".或“错误";的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                问题描述

                我收到声纳违规:

                <块引用>

                条件不应无条件地评估为TRUE"或FALSE""

                下面的代码.

                列表<媒体内容>savedList = source.getChildMediaContents();列出<媒体内容>供应商列表 = target.getChildMediaContents();//如果存在和传入都是空的如果(保存列表 == 空 && 供应商列表 == 空){返回假;}//如果一个为空,另一个不为空,则需要更新if(savedList == null && 供应商列表!= null){返回真;}if(savedList != null && supplierList == null){返回真;}

                在两个 if 块下面会报错

                //如果一个为空,另一个不为空,则需要更新if(savedList == null && 供应商列表!= null){返回真;}if(savedList != null && supplierList == null){返回真;}

                解决方案

                if(savedList == null && supplierList == null){返回假;}if(savedList == null && 供应商列表!= null){

                条件 supplierList != null 在达到时始终为真.由于 Java 中 && 运算符的短路行为,在 supplierList != null 到达之前,savedList == null 必须首先为真.

                但如果 savedList == null 为真,那么我们从前面的条件知道supplierList不是null,所以这是一个没有意义的条件.

                另一方面,如果 savedList == null 为假,然后由于短路行为,supplierList != null 将不会被评估.

                因此,无论 savedList == null 的结果如何,supplierList != null 永远不会被评估,所以你可以简单地删除那个条件.

                if (savedList == null) {返回真;}

                下一步:

                <块引用>

                if(savedList != null && supplierList == null){

                感谢之前的简化,现在很明显 savedList 不能为 null.所以我们也可以去掉那个条件:

                if (supplierList == null) {返回真;}

                简而言之,这相当于你发布的代码:

                if (savedList == null && supplierList == null) {返回假;}if (savedList == null || 供应商列表 == null) {返回真;}

                I am getting sonar violation:

                "Conditions should not unconditionally evaluate to "TRUE" or to "FALSE""

                for the code below.

                List<MediaContent> savedList = source.getChildMediaContents();
                List<MediaContent> supplierList = target.getChildMediaContents();
                
                // if existing and incoming both empty
                if(savedList == null && supplierList == null){
                    return false;
                }
                
                // if one is null and other is not then update is required
                if(savedList == null && supplierList != null){
                    return true;
                }
                
                if(savedList != null && supplierList == null){
                    return true;
                }
                

                Below the two if blocks it is giving an error

                // if one is null and other is not then update is required
                if(savedList == null && supplierList != null){
                    return true;
                }
                
                if(savedList != null && supplierList == null){
                    return true;
                }
                

                解决方案

                if(savedList == null && supplierList == null){
                    return false;
                }
                
                if(savedList == null && supplierList != null){
                

                The condition supplierList != null is always true when reached. Due to the short-circuiting behavior of the && operator in Java, before supplierList != null is reached, savedList == null must be true first.

                But if savedList == null is true, then we know from the previous condition that supplierList is not null, so it's a pointless condition.

                On the other hand, if savedList == null is false, then the due to the short-circuiting behavior, the supplierList != null will not be evaluated.

                Thus, regardless of the outcome of savedList == null, supplierList != null will never be evaluated, so you can simply remove that condition.

                if (savedList == null) {
                    return true;
                }
                

                Next:

                if(savedList != null && supplierList == null){
                

                Thanks to the simplification earlier, now it's clear that savedList cannot be null. So we can remove that condition too:

                if (supplierList == null) {
                    return true;
                }
                

                In short, this is equivalent to your posted code:

                if (savedList == null && supplierList == null) {
                    return false;
                }
                
                if (savedList == null || supplierList == null) {
                    return true;
                }
                

                这篇关于声纳错误条件不应无条件地评估为“真".或“错误";的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

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

                相关文档推荐

                How to send data to COM PORT using JAVA?(如何使用 JAVA 向 COM PORT 发送数据?)
                How to make a report page direction to change to quot;rtlquot;?(如何使报表页面方向更改为“rtl?)
                Use cyrillic .properties file in eclipse project(在 Eclipse 项目中使用西里尔文 .properties 文件)
                Is there any way to detect an RTL language in Java?(有没有办法在 Java 中检测 RTL 语言?)
                How to load resource bundle messages from DB in Java?(如何在 Java 中从 DB 加载资源包消息?)
                How do I change the default locale settings in Java to make them consistent?(如何更改 Java 中的默认语言环境设置以使其保持一致?)
                1. <tfoot id='QPqpb'></tfoot>
                  <i id='QPqpb'><tr id='QPqpb'><dt id='QPqpb'><q id='QPqpb'><span id='QPqpb'><b id='QPqpb'><form id='QPqpb'><ins id='QPqpb'></ins><ul id='QPqpb'></ul><sub id='QPqpb'></sub></form><legend id='QPqpb'></legend><bdo id='QPqpb'><pre id='QPqpb'><center id='QPqpb'></center></pre></bdo></b><th id='QPqpb'></th></span></q></dt></tr></i><div id='QPqpb'><tfoot id='QPqpb'></tfoot><dl id='QPqpb'><fieldset id='QPqpb'></fieldset></dl></div>
                2. <legend id='QPqpb'><style id='QPqpb'><dir id='QPqpb'><q id='QPqpb'></q></dir></style></legend>

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

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