提交 66554db3 authored 作者: Thomas Mueller's avatar Thomas Mueller

JdbcConnectionPool.getConnection() could throw a NullPointerException.

上级 f7bac66f
...@@ -52,8 +52,12 @@ implements XAConnection, XAResource ...@@ -52,8 +52,12 @@ implements XAConnection, XAResource
private JdbcDataSourceFactory factory; private JdbcDataSourceFactory factory;
private String url, user; private String url, user;
// This connection is kept open as long as the XAConnection is alive
private JdbcConnection physicalConn; private JdbcConnection physicalConn;
private PooledJdbcConnection handleConn;
// This connection is replaced whenever getConnection is called
private volatile PooledJdbcConnection handleConn;
private ArrayList<ConnectionEventListener> listeners = New.arrayList(); private ArrayList<ConnectionEventListener> listeners = New.arrayList();
private Xid currentTransaction; private Xid currentTransaction;
private int currentTransactionId; private int currentTransactionId;
...@@ -95,9 +99,10 @@ implements XAConnection, XAResource ...@@ -95,9 +99,10 @@ implements XAConnection, XAResource
//## Java 1.4 begin ## //## Java 1.4 begin ##
public void close() throws SQLException { public void close() throws SQLException {
debugCodeCall("close"); debugCodeCall("close");
if (handleConn != null) { PooledJdbcConnection lastHandle = handleConn;
if (lastHandle != null) {
listeners.clear(); listeners.clear();
handleConn.close(); lastHandle.close();
} }
if (physicalConn != null) { if (physicalConn != null) {
try { try {
...@@ -119,8 +124,9 @@ implements XAConnection, XAResource ...@@ -119,8 +124,9 @@ implements XAConnection, XAResource
//## Java 1.4 begin ## //## Java 1.4 begin ##
public Connection getConnection() throws SQLException { public Connection getConnection() throws SQLException {
debugCodeCall("getConnection"); debugCodeCall("getConnection");
if (handleConn != null) { PooledJdbcConnection lastHandle = handleConn;
handleConn.close(); if (lastHandle != null) {
lastHandle.close();
} }
handleConn = new PooledJdbcConnection(physicalConn); handleConn = new PooledJdbcConnection(physicalConn);
return handleConn; return handleConn;
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论