【发布时间】:2017-12-12 16:02:23
【问题描述】:
我有这样的代码:
public static MyObject forId(long myObjectId, Connection cxn) throws SQLException {
try (PreparedStatement stmt = cxn.prepareStatement(selectMyObjectById))) {
stmt.setLong(1, myObjectId);
try (ResultSet res = stmt.executeQuery()) {
res.next();
return MyObject.fromResultSet(res);
}
}
}
对于 JDBC Statement 对象,SpotBugs 将其标识为 OBL_UNSATISFIED_OBLIGATION。这是误报吗?我的印象是 try-with-resources 将确保这些资源在所有情况下都能正确关闭。
【问题讨论】:
标签: java try-with-resources spotbugs