I don't know why eclipse warn me "Dead Code" in this code of mine:
PreparedStatement p = conn.prepareStatement("SELECT name FROM user WHERE age = ? , city = ?");
p.setInt(1, (String) parameters.get("age"));
p.setString(2, (String) parameters.get("city"));
if (p == null) {
log.warn("User is not available");
return results;
}
the warning was in the log, can anybody tell me the reason of this? thank you.
p
can not be null
at that point, simply because you already called setInt
and setString
on p
and if it were null
there, then it would have thrown a NullPointerException
, thus never reaching your if
.
Also note that according to its documentation, preparedStatement
can't ever return null
. It can only return a valid statement or throw an exception. In the latter case your if
will also not be reached. That fact, however, is not checked by the compiler (because a broken implementation of prepareStatement
could theoretically return null
).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With