提交 36ed8325 authored 作者: Thomas Mueller's avatar Thomas Mueller

If a pooled connection was not closed but garbage collected, a NullPointerException could occur.

上级 b6d235be
......@@ -18,7 +18,8 @@ Change Log
<h1>Change Log</h1>
<h2>Next Version (unreleased)</h2>
<ul><li>Fulltext search: a NullPointerException was thrown when updating a value that
<ul><li>If a pooled connection was not closed but garbage collected, a NullPointerException could occur.
</li><li>Fulltext search: a NullPointerException was thrown when updating a value that
was NULL previously.
</li><li>The Recover tool did not work with .data.db files of the wrong size.
</li><li>Triggers: if there was an exception when initializing a trigger, this exception could be hidden,
......
......@@ -59,6 +59,12 @@ import java.sql.SQLClientInfoException;
* </p>
*/
public class JdbcConnection extends TraceObject implements Connection {
/**
* The stack trace of when the connection was created.
*/
protected Exception openStackTrace;
private String url;
private String user;
......@@ -71,7 +77,6 @@ public class JdbcConnection extends TraceObject implements Connection {
private CommandInterface getReadOnly, getGeneratedKeys;
private CommandInterface setLockMode, getLockMode;
private CommandInterface setQueryTimeout, getQueryTimeout;
private Exception openStackTrace;
//## Java 1.4 begin ##
private int savepointId;
......@@ -285,6 +290,7 @@ public class JdbcConnection extends TraceObject implements Connection {
public synchronized void close() throws SQLException {
try {
debugCodeCall("close");
openStackTrace = null;
if (executingStatement != null) {
executingStatement.cancel();
}
......@@ -1320,7 +1326,7 @@ public class JdbcConnection extends TraceObject implements Connection {
if (isInternal) {
return;
}
if (session != null) {
if (session != null && openStackTrace != null) {
trace.error("Connection not closed", openStackTrace);
try {
close();
......
......@@ -20,6 +20,7 @@ import javax.transaction.xa.XAException;
import javax.transaction.xa.XAResource;
import javax.transaction.xa.Xid;
import org.h2.constant.ErrorCode;
import org.h2.constant.SysProperties;
import org.h2.jdbc.JdbcConnection;
import org.h2.util.ByteUtils;
import org.h2.util.JdbcUtils;
......@@ -28,6 +29,7 @@ import org.h2.util.StringUtils;
//## Java 1.4 end ##
import org.h2.message.Message;
import org.h2.message.Trace;
import org.h2.message.TraceObject;
/*## Java 1.6 begin ##
......@@ -94,6 +96,7 @@ implements XAConnection, XAResource
public void close() throws SQLException {
debugCodeCall("close");
if (handleConn != null) {
listeners.clear();
handleConn.close();
}
if (physicalConn != null) {
......@@ -479,6 +482,7 @@ implements XAConnection, XAResource
public PooledJdbcConnection(JdbcConnection conn) {
super(conn);
openStackTrace = new Exception("Stack Trace");
}
public synchronized void close() throws SQLException {
......@@ -501,6 +505,21 @@ implements XAConnection, XAResource
super.checkClosed(write);
}
protected void finalize() {
if (!SysProperties.runFinalize) {
return;
}
Trace trace = getTrace();
try {
if (!isClosed()) {
trace.error("Pooled connection not closed", openStackTrace);
JdbcXAConnection.this.close();
}
} catch (SQLException e) {
trace.debug("finalize", e);
}
}
}
}
......@@ -131,7 +131,7 @@ public class TraceObject {
}
/**
* Update the trace.
* Update the trace object.
*
* @param trace the trace object
*/
......@@ -139,6 +139,15 @@ public class TraceObject {
this.trace = trace;
}
/**
* Get the trace object.
*
* @return the trace object
*/
protected Trace getTrace() {
return trace;
}
/**
* INTERNAL
*/
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论