squid:S2583 :更改此条件,使其不总是计算为 "true"

squid:S2583 : Change this condition so that it does not always evaluate to "true"

S2583:如何更改条件 ps != null,使其不总是求值为 "false"?

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

如果 ps 不为空,因为你总是给它设置一个值(在你省略的行),条件语句是完全多余的,你可以消除条件。

来自 squid:S2583 描述:

Conditional statements using a condition which cannot be anything but FALSE have the effect of making blocks of code non-functional. If the condition cannot evaluate to anything but TRUE, the conditional statement is completely redundant, and makes the code less readable.