Method com.hysoft.cache.mgmt.bulkload.DomLoad.getTotalNum(long, String) may fail to clean up java.sql.Statement
This method may fail to clean up (close, dispose of) a stream, database object, or other resource requiring an explicit cleanup operation.
In general, if a method opens a stream or other resource, the method should use a try/finally block to ensure that the stream or resource is cleaned up before the method returns.
This bug pattern is essentially the same as the OS_OPEN_STREAM and ODR_OPEN_DATABASE_RESOURCE bug patterns, but is based on a different (and hopefully better) static analysis technique. We are interested is getting feedback about the usefulness of this bug pattern. To send feedback, either:
In particular, the false-positive suppression heuristics for this bug pattern have not been extensively tuned, so reports about false positives are helpful to us.
See Weimer and Necula, Finding and Preventing Run-Time Error Handling Mistakes, for a description of the analysis technique.
解决办法:
try{
....
} catch (Exception e) {
LOG.info(e);
e.printStackTrace();
} finally {
try {
if (resultSet != null) {
resultSet.close();
}
} catch (SQLException e) {
LOG.info(e);
e.printStackTrace();
}
try {
if (ps != null) {
ps.close();
}
} catch (SQLException e) {
LOG.info(e);
e.printStackTrace();
}
try {
if (connection != null) {
connection.close();
}
} catch (SQLException e) {
LOG.info(e);
e.printStackTrace();
}
}
分享到:
相关推荐
To make use of either more or less strict isolation levels in applications, locking can be customized for an entire session by setting the isolation level of the session with the SET TRANSACTION ...
2. OBL: Method may fail to clean up stream or resource (OBL_UNSATISFIED_OBLIGATION) 这个警告提醒开发者注意资源管理问题,即方法可能未正确关闭或释放流、数据库对象等。使用try-with-resources语句或try-...
2. OBL: Method may fail to clean up stream or resource (OBL_UNSATISFIED_OBLIGATION) 方法可能没有正确地清理流或资源,这违反了良好的编程实践,即在打开资源后必须关闭它们。使用try-with-resources或try-...
8. Experimental: OBL: Method may fail to clean up stream or resource (OBL_UNSATISFIED_OBLIGATION) 方法可能没有正确清理流、数据库连接等资源。应当使用try/finally块或try-with-resources语句确保资源在方法...
##### OBL:Method may fail to cleanup stream or resource (OBL_UNSATISFIED_OBLIGATION) **描述**: 方法可能没有正确地关闭流或释放其他资源。 **问题**: 资源泄漏可能导致性能下降或者系统崩溃。 **建议**: 使用...