简体   繁体   English

squid:S2583:更改此条件,以便它并不总是评估为“ true”

[英]squid:S2583 : Change this condition so that it does not always evaluate to “true”

S2583: How can the condition ps != null be changed so that it does not always evaluate to "false"? S2583:如何更改条件ps != null ,以使其始终不等于“ false”?

PreparedStatement ps = null;
if (ps != null) {
  try {
    ps.close();
  } catch (SQLException uncatched) {
     uncatched.printStackTrace();
  }
}

if ps is not null because you always set a value to it (at lines that you omitted), the conditional statement is completely redundant and you can eliminate the condition. 如果ps不为null,因为您总是为它设置一个值(在省略的行中),那么条件语句是完全多余的,您可以消除该条件。

From squid:S2583 description: 来自鱿鱼:S2583说明:

Conditional statements using a condition which cannot be anything but FALSE have the effect of making blocks of code non-functional. 使用条件不能为FALSE的条件语句会导致使代码块不起作用。 If the condition cannot evaluate to anything but TRUE, the conditional statement is completely redundant, and makes the code less readable. 如果条件不能评估为TRUE,则条件语句将完全多余,并使代码的可读性降低。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 SonarQube 鱿鱼中的假阳性:S2583 - False positive in SonarQube squid:S2583 鱿鱼:S2583 –使用开关时,Sonarqube误报 - squid:S2583 – Sonarqube false positive when using switch 声纳更改此条件,以使其始终不等于“ true”。 假阳性 - Sonar Change this condition so that it does not always evaluate to “true”. False positive Sonal lint :更改此条件,使其不总是评估为真 - Sonal lint : change this condition so that it does not always evaluate to true SonarQube:更改此条件,使其不总是评估为真 - SonarQube: Change this condition so that it does not always evaluate to true 更改此条件,以使其始终不等于“ false” - Change this condition so that it does not always evaluate to “false” 声纳假阳性,“改变条件,使其不总是评估为真。” - Sonar false positive, “change condition so that it does not always evaluate to true.” 如何避免“更改此条件,使其不总是评估为“假”” - How to avoid "Change this condition so that it does not always evaluate to "false"" “更改此条件,以便它不总是评估为假”-SonarQube - “Change this condition so that it does not always evaluate to false” - SonarQube SONAR抱怨改变条件,因此它并不总是评估为“假” - SONAR complaining to change the condition so that it does not always evaluate to “false”
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM