現(xiàn)狀:XAPool1.4有一個bug,當(dāng)設(shè)置preparedStmtCacheSize=0的時候,關(guān)閉連接會拋出NullPointerException
原因:StandardConnectionHandle在Close的時候調(diào)用了preparedStatementCache.cleanupAll(),沒有進行判斷;而當(dāng)preparedStmtCacheSize設(shè)置為0的時候,StandardConnectionHandle在setupPreparedStatementCache中把preparedStatementCache設(shè)置為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;
}