现状: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;
}