代碼:Java嘗試抓住,最後。如果發生異常,最終還是會保留參考?
try {
dbConnection = jdbcTemplate.getDataSource().getConnection();
callableStatement = dbConnection.prepareCall(getDBUSERCursorSql);
}
catch (SQLException e) {
LOGGER.error("Error occured", e);
}
finally
{
if (dbConnection != null && !dbConnection.isClosed()) {
dbConnection.close();
}
}
因此,如果在線路的CallableStatement = dbConnection.prepareCall(getDBUSERCursorSql)發生異常;並且catch塊執行後,將會在finally塊中仍然存在對dbConnection
的引用嗎? Fortify說不,但我不確定增強是否正確。
nope,因爲異常將在賦值之前拋出 – JohnnyAW
我認爲只要'dbConnection'被定義在'try catch'之外鎖定它仍然存在。試一試? :) –
@ EM-Creations這個問題不是關於變量是否可用,它關於對dbConnection的引用:) – JohnnyAW