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.
pcan not benullat that point, simply because you already calledsetIntandsetStringonpand if it werenullthere, then it would have thrown aNullPointerException, thus never reaching yourif.Also note that according to its documentation,
preparedStatementcan’t ever returnnull. It can only return a valid statement or throw an exception. In the latter case yourifwill also not be reached. That fact, however, is not checked by the compiler (because a broken implementation ofprepareStatementcould theoretically returnnull).