現(xiàn)狀:XAPool1.4有一個bug,當設置preparedStmtCacheSize=0的時候,關閉連接會拋出NullPointerException
原因:StandardConnectionHandle在Close的時候調用了preparedStatementCache.cleanupAll(),沒有進行判斷;而當preparedStmtCacheSize設置為0的時候,StandardConnectionHandle在setupPreparedStatementCache中把preparedStatementCache設置為null,以下setupPreparedStatementCache是方法中的源代碼片斷:
protected void setupPreparedStatementCache() {
log.debug("StandardConnectionHandle:setupPreparedStatementCache start");
if (preparedStmtCacheSize == 0) {
log.debug(
"StandardConnectionHandle:setupPreparedStatementCache return with 0");
preparedStatementCache = null;
return;
}
解決辦法:修改setupPreparedStatementCache,如下:
if (preparedStmtCacheSize == 0) {
log.debug(
"StandardConnectionHandle:setupPreparedStatementCache return with 0");
// preparedStatementCache = null;
preparedStatementCache = new PreparedStatementCache(0);
return;
}