【问题标题】:Sonarqube (Version 4.5): Condition should not unconditionally evaluate to TRUE or FALSESonarqube(4.5 版):条件不应无条件地评估为 TRUE 或 FALSE
【发布时间】:2017-05-17 03:06:19
【问题描述】:

Sonar 在 null != textEditor 处显示错误。

TextEditor textEditor = null;

try{
   /* Initialize text editor for the current operation */
   textEditor = textEditorFactory.getCurrentEditingContext();
   if(null == textEditor){
     return;
   }
   /* doSomeOperation */
} catch (final Exception e) {
   if (null != textEditor) {
    textEditor.cancelEdit();
   }
}

错误消息:更改此条件,使其不总是 评估为“假”。

【问题讨论】:

  • 您能准确地说出您使用的是哪种语言吗? (我猜是 Java 吗?)您能否准确地说一下 SonarJava Analyzer 的版本是什么?

标签: java sonarqube


【解决方案1】:

textEditor 在 catch 块中唯一的值是 null。这是因为如果在 try 块中抛出异常,它只能来自 getCurrentEditingContext() 调用,在这种情况下 textEditor 仍然是 null

【讨论】:

    猜你喜欢
    • 2017-05-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-03-15
    • 1970-01-01
    • 2017-12-18
    • 1970-01-01
    相关资源
    最近更新 更多